From: Shung-Hsi Yu <shung-hsi.yu@suse.com>
To: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
Cc: Eduard Zingerman <eddyz87@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
John Fastabend <john.fastabend@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] bpf: Preserve stack frame number for commuted arithmetic
Date: Wed, 22 Jul 2026 16:46:30 +0800 [thread overview]
Message-ID: <amB_My3Pg2hIxRG7@u94a> (raw)
In-Reply-To: <976ae2fbf6f2ead76622e39813bfda6a6981d382.camel@gmail.com>
On Tue, Jul 21, 2026 at 05:12:14PM -0700, Eduard Zingerman wrote:
> On Tue, 2026-07-21 at 09:39 +0000, Yiyang Chen wrote:
> > When scalar += pointer is handled in adjust_ptr_min_max_vals(), the
> > destination register has to inherit the pointer register state from the
> > source pointer. Copying only selected fields is fragile because pointer
> > provenance is tracked by several bpf_reg_state fields.
> >
> > For the commuted form, pass a temporary scalar offset register to the
> > common pointer arithmetic helper and copy the full pointer state before
> > applying pointer arithmetic. This preserves the frame number for
> > PTR_TO_STACK registers and keeps parent identity fields consistent.
> >
> > Fixes: f1174f77b50c ("bpf/verifier: rework value tracking")
This doesn't look right. Without bpf2bpf there is just one frame, hence
there isn't a bug at this point. I think the commit f4d7e40a5b71 ("bpf:
introduce function calls (verification)") the you mentioned in v1 should
be used here instead.
Ideally there should be a second tag for the missed parent_id
preservation issue for invalidating dynptr mentioned by Sashiko, too.
But it wasn't that obvious where that issue was introduced to me, and
f4d7e40a5b71 pre-dates dynptr anyway.
> > Signed-off-by: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>
> > ---
> > kernel/bpf/verifier.c | 14 +++++++++-----
> > 1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 52be0a118cce0..3c0af83db4672 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -13796,11 +13796,12 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
> > return -EACCES;
> > }
> >
> > - /* In case of 'scalar += pointer', dst_reg inherits pointer type and id.
> > - * The id may be overwritten later if we create a new variable offset.
> > + /* For 'scalar += pointer', dst_reg inherits the complete pointer
> > + * register state. Individual fields may be adjusted later by pointer
> > + * arithmetic.
> > */
> > - dst_reg->type = ptr_reg->type;
> > - dst_reg->id = ptr_reg->id;
> > + if (ptr_reg != dst_reg)
> > + *dst_reg = *ptr_reg;
>
> Lot's of tests are failing on the CI, please investigate.
I think one reason is that this overwrites r64 and var_off, hence in the
scalar += pointer case, we're adding the existing offset in ptr_reg to
itself, equivalent to:
dst_reg->r64 = cnum64_add(ptr_reg->r64, ptr_reg->r64);
dst_reg->var_off = tnum_add(ptr_reg->var_off, ptr_reg->var_off);
[...]
next prev parent reply other threads:[~2026-07-22 8:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 9:39 [bpf-next v2 0/2] bpf: Preserve stack frame number for commuted arithmetic Yiyang Chen
2026-07-21 9:39 ` [PATCH 1/2] " Yiyang Chen
2026-07-21 9:48 ` sashiko-bot
2026-07-22 7:44 ` Shung-Hsi Yu
2026-07-22 0:12 ` Eduard Zingerman
2026-07-22 8:46 ` Shung-Hsi Yu [this message]
2026-07-21 9:39 ` [PATCH 2/2] selftests/bpf: Cover stack frame number after scalar plus fp Yiyang Chen
2026-07-21 10:29 ` bot+bpf-ci
2026-07-21 23:53 ` Eduard Zingerman
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=amB_My3Pg2hIxRG7@u94a \
--to=shung-hsi.yu@suse.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenyy23@mails.tsinghua.edu.cn \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--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