From: Eduard Zingerman <eddyz87@gmail.com>
To: Daniel Xu <dxu@dxuuu.xyz>, Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: andrii@kernel.org, ast@kernel.org, shuah@kernel.org,
daniel@iogearbox.net, john.fastabend@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
jolsa@kernel.org, mykolal@fb.com, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 4/5] bpf: verifier: Support eliding map lookup nullness
Date: Thu, 19 Dec 2024 16:04:43 -0800 [thread overview]
Message-ID: <a2999d8b4827516fe4bfd17646d2284580712d08.camel@gmail.com> (raw)
In-Reply-To: <kghvgxu5wdkupssnq7dy5upuf2wscsxgsnwl2yoam4mwk3h5pn@wjjsliwg6fzl>
On Thu, 2024-12-19 at 14:41 -0700, Daniel Xu wrote:
[...]
> > > I think that if test operates on a key like:
> > >
> > > valid key 15
> > > v
> > > 0000000f <-- written to stack as a single u64 value
> > > ^^^^^^^
> > > stack zero marks
> > >
> > > and is executed (e.g. using __retval annotation),
> > > then CI passing for s390 should be enough.
> >
> > +1, something like that where for big-endian it will be all zero while
> > for little endian it would be 0xf (and then make sure that the test
> > should *fail* by making sure that 0xf is not a valid index, so NULL
> > check is necessary)
>
> How would it work for LE to be 0xF but BE to be 0x0?
>
> The prog passes a pointer to the beginning of the u32 to
> bpf_map_lookup_elem(). The kernel does a 4 byte read starting from that
> address. On both BE and LE all 4 bytes will be interpreted. So set bits
> cannot just go away.
>
> Am I missing something?
Ok, thinking a bit more, the best test I can come up with is:
u8 vals[8];
vals[0] = 0;
...
vals[6] = 0;
vals[7] = 0xf;
p = bpf_map_lookup_elem(... vals ...);
*p = 42;
For LE vals as u32 should be 0x0f;
For BE vals as u32 should be 0xf000_0000.
Hence, it is not safe to remove null check for this program.
What would verifier think about the value of such key?
As far as I understand, there would be stack zero for for vals[0-6]
and u8 stack spill for vals[7].
You were going to add a check for the spill size, which should help here.
So, a negative test like above that checks that verifier complains
that 'p' should be checked for nullness first?
If anyone has better test in mind, please speak-up.
[...]
next prev parent reply other threads:[~2024-12-20 0:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-12 23:22 [PATCH bpf-next v5 0/5] Support eliding map lookup nullness Daniel Xu
2024-12-12 23:22 ` [PATCH bpf-next v5 3/5] bpf: verifier: Refactor helper access type tracking Daniel Xu
2024-12-13 4:04 ` Eduard Zingerman
2024-12-13 20:02 ` Daniel Xu
2024-12-12 23:22 ` [PATCH bpf-next v5 4/5] bpf: verifier: Support eliding map lookup nullness Daniel Xu
2024-12-13 4:04 ` Eduard Zingerman
2024-12-13 20:57 ` Daniel Xu
2024-12-13 23:02 ` Andrii Nakryiko
2024-12-14 2:44 ` Daniel Xu
2024-12-14 3:13 ` Eduard Zingerman
2024-12-16 23:24 ` Andrii Nakryiko
2024-12-19 0:09 ` Daniel Xu
2024-12-19 21:41 ` Daniel Xu
2024-12-20 0:04 ` Eduard Zingerman [this message]
2024-12-20 0:40 ` Daniel Xu
2024-12-20 0:43 ` Eduard Zingerman
2024-12-20 0:49 ` Alexei Starovoitov
2024-12-20 4:00 ` Daniel Xu
2024-12-13 23:10 ` Kumar Kartikeya Dwivedi
2024-12-13 23:14 ` Eduard Zingerman
2024-12-13 23:18 ` Eduard Zingerman
2024-12-12 23:22 ` [PATCH bpf-next v5 5/5] bpf: selftests: verifier: Add nullness elision tests Daniel Xu
2024-12-14 6:17 ` Eduard Zingerman
2024-12-18 1:57 ` Daniel Xu
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=a2999d8b4827516fe4bfd17646d2284580712d08.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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