From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
Shung-Hsi Yu <shung-hsi.yu@suse.com>
Subject: [RFC bpf-next 0/2] bpf: tnums: warn against the usage of tnum_in(tnum_range(), ...)
Date: Wed, 31 Aug 2022 11:19:05 +0800 [thread overview]
Message-ID: <20220831031907.16133-1-shung-hsi.yu@suse.com> (raw)
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
next reply other threads:[~2022-08-31 3:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 3:19 Shung-Hsi Yu [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220831031907.16133-1-shung-hsi.yu@suse.com \
--to=shung-hsi.yu@suse.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®