From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
bpf <bpf@vger.kernel.org>,
kkd@meta.com, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Manu Bretelle <chantra@meta.com>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH bpf v1 2/2] selftests/bpf: Add raw_tp tests for PTR_MAYBE_NULL marking
Date: Wed, 04 Dec 2024 13:37:24 -0800 [thread overview]
Message-ID: <4d96bbb0433d4fdd285b9fe12cdfe9259d8b929f.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQ+ObWEF4g_FVrwFJF4gnkmBB=4UcnGZV5jaJ3SffyG0HQ@mail.gmail.com>
On Wed, 2024-12-04 at 13:13 -0800, Alexei Starovoitov wrote:
> On Wed, Dec 4, 2024 at 1:08 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Wed, 2024-12-04 at 21:48 +0100, Kumar Kartikeya Dwivedi wrote:
> >
> > [...[
> >
> > (A) ----.
> > |
> > v
> > > > > What this will do in both cases::
> > > > > First, avoid walking states when off != 0, and reset id.
> > > > > If off == 0, go inside mark_ptr_or_null_reg and walk all regs, and
> > > > > remove marks for those with off != 0.
> >
> > (B) ----.
> > |
> > v
> > > > That's getting intrusive.
> > > > How about we reset id=0 in adjust_ptr_min_max_vals()
> > > > right after we suppressed "null-check it first" message for raw_tp-s.
> > > >
> > > > That will address the issue as well, right?
> > >
> > > Yes (minor detail, it needs to be reset to a new id, otherwise we have
> > > warn on maybe_null set but !reg->id, but the idea is the same).
> > > Let's see what Eduard thinks and then I can give it a go.
> >
> > Sorry for delay.
> >
> > I like what Kumar is proposing in (A) because it could be generalized:
> > there is no real harm in doing 'r2 = r1; r2 += 8; r1 != 0; ...'
> > and what Kumar suggests could be used to lift the "null-check it first ..."
> > restriction.
>
> I don't see how it can be generalized.
> Also 'avoid walking states when off != 0' is far from simple.
> We call into mark_ptr_or_null_regs() with id == 0 already
> and with reg->off != 0 for RCU and alloc_obj.
I did not try to implement this, so there might be a devil in the details.
The naive approach looks as below.
Suppose we want to allow 'rX += K' when rX is PTR_MAYBE_NULL.
Such operations generate a set of pointers with different .off values
but same .id .
For a regular (non raw_tp) case:
- dereferencing PTR_MAYBE_NULL is disallowed;
- if there is a check 'if rY != 0' and rY.off == 0,
the non-null status could be propagated to each
register in a set (and PTR_MAYBE_NULL mark removed);
- if there is a check 'if rY != 0' and rY.off != 0,
nothing happens, no marks are changed.
For a raw_tp case:
- dereferencing PTR_MAYBE_NULL is allowed (as it is already);
- the mechanics for 'if rY != 0' and rY.off ==/!= 0 can remain the same,
nothing is wrong with removing PTR_MAYBE_NULL marks from such pointers.
> 'avoid walking with off != 0' doesn't look trivial.
> It would need to be special cased to raw_tp and some other
> conditions.
> I could be missing something.
>
> Let's see how patches look.
>
> > However, as far as I understand, the plan is to fix this by generating
> > two entry tracepoint states: one with parameter as null, another with
> > parameter not-null (all combinations for every parameter).
> > If that is the plan, what Alexei suggests in (B) is simpler.
next prev parent reply other threads:[~2024-12-04 21:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 2:41 [PATCH bpf v1 0/2] Fix for raw_tp PTR_MAYBE_NULL unmarking Kumar Kartikeya Dwivedi
2024-12-04 2:41 ` [PATCH bpf v1 1/2] bpf: Suppress warning for non-zero off raw_tp arg NULL check Kumar Kartikeya Dwivedi
2024-12-04 16:37 ` Alexei Starovoitov
2024-12-04 18:55 ` Kumar Kartikeya Dwivedi
2024-12-04 2:41 ` [PATCH bpf v1 2/2] selftests/bpf: Add raw_tp tests for PTR_MAYBE_NULL marking Kumar Kartikeya Dwivedi
2024-12-04 20:12 ` Eduard Zingerman
2024-12-04 20:19 ` Kumar Kartikeya Dwivedi
2024-12-04 20:22 ` Kumar Kartikeya Dwivedi
2024-12-04 20:40 ` Alexei Starovoitov
2024-12-04 20:48 ` Kumar Kartikeya Dwivedi
2024-12-04 21:08 ` Eduard Zingerman
2024-12-04 21:13 ` Alexei Starovoitov
2024-12-04 21:37 ` Eduard Zingerman [this message]
2024-12-04 22:08 ` Kumar Kartikeya Dwivedi
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=4d96bbb0433d4fdd285b9fe12cdfe9259d8b929f.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chantra@meta.com \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
/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