From: Eduard Zingerman <eddyz87@gmail.com>
To: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: 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: Tue, 21 Jul 2026 17:12:14 -0700 [thread overview]
Message-ID: <976ae2fbf6f2ead76622e39813bfda6a6981d382.camel@gmail.com> (raw)
In-Reply-To: <a092a059781aad37b8d8ce3bb927052de5f73431.1784563950.git.chenyy23@mails.tsinghua.edu.cn>
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")
> 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.
>
> if (!check_reg_sane_offset_scalar(env, off_reg, ptr_reg->type) ||
> !check_reg_sane_offset_ptr(env, ptr_reg, ptr_reg->type))
> @@ -14854,15 +14855,18 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
> bpf_alu_string[opcode >> 4]);
> return -EACCES;
> } else {
> + struct bpf_reg_state off_reg;
> +
We store such temporaries in the bpf_verifier_env to avoid excessive
stack consumption.
> /* scalar += pointer
> * This is legal, but we have to reverse our
> * src/dest handling in computing the range
> */
> + off_reg = *dst_reg;
> err = mark_chain_precision(env, insn->dst_reg);
> if (err)
> return err;
> return adjust_ptr_min_max_vals(env, insn,
> - src_reg, dst_reg);
> + src_reg, &off_reg);
> }
> } else if (ptr_reg) {
> /* pointer += scalar */
>
> base-commit: 0bcca2a42cc50b7d64a95c08dffc6b93661a7ea2
next prev parent reply other threads:[~2026-07-22 0:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 9:39 [bpf-next v2 0/2] " Yiyang Chen
2026-07-21 9:39 ` [PATCH 1/2] " Yiyang Chen
2026-07-22 0:12 ` Eduard Zingerman [this message]
2026-07-22 8:46 ` Shung-Hsi Yu
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=976ae2fbf6f2ead76622e39813bfda6a6981d382.camel@gmail.com \
--to=eddyz87@gmail.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=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
all inboxes | Powered by JetHome®