mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC bpf-next 0/2] bpf: tnums: warn against the usage of tnum_in(tnum_range(), ...)
@ 2022-08-31  3:19 Shung-Hsi Yu
  2022-08-31  3:19 ` [RFC bpf-next 1/2] " Shung-Hsi Yu
  2022-08-31  3:19 ` [RFC bpf-next 2/2] proof for the safe usage of tnum_in() Shung-Hsi Yu
  0 siblings, 2 replies; 6+ messages in thread
From: Shung-Hsi Yu @ 2022-08-31  3:19 UTC (permalink / raw)
  To: bpf, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend, Shung-Hsi Yu

Commit a657182a5c51 ("bpf: Don't use tnum_range on array range checking
for poke descriptors") has shown that using tnum_range() as argument to
tnum_in() can lead to misleading code that looks like tight bound check
when in fact the actual allowed range is much wider.

This patchset is a follow up of the above commit. I've audited other
usage of tnum_in() in verifier and have concluded that all of either
provides a tight bound check, or is using reg->var_off as the first
argument, and thus safe.

To prevent the problematic tnum_in(tnum_range(), ...) usage, add
documentation in the tnum.h header file to warn against it.

This is sent as an RFC for two reasons:
1. Gather feedback on whether it's possible to prevent the problematic
   usage besides relying just on documentation. 

   One invasive option is to switch bound-checks done with
   tnum_in(tnum_range(), ...) to use reg->u{min,max}_value instead,
   which should always provide a tight bound check.

   Alternatively maybe problematic usage can be detected through
   development tool (sparse or Coccinelle?), but I know rather little
   about them.
   
2. Attach a proof for the claimed safe usage of tnum_in(tnum_range(), ...)
   found in patch 1, where the proof itself is not meant to be
   merged.

Shung-Hsi Yu (2):
  bpf: tnums: warn against the usage of tnum_in(tnum_range(), ...)
  proof for the safe usage of tnum_in()

 include/linux/tnum.h |  20 +++++-
 tnum_in.py           | 158 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 2 deletions(-)
 create mode 100755 tnum_in.py

-- 
2.37.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-02 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-31  3:19 [RFC bpf-next 0/2] bpf: tnums: warn against the usage of tnum_in(tnum_range(), ...) Shung-Hsi Yu
2022-08-31  3:19 ` [RFC bpf-next 1/2] " Shung-Hsi Yu
2022-09-01 15:00   ` Daniel Borkmann
2022-09-02  3:52     ` Shung-Hsi Yu
2022-09-02 12:47       ` Daniel Borkmann
2022-08-31  3:19 ` [RFC bpf-next 2/2] proof for the safe usage of tnum_in() Shung-Hsi Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®