From: bot+bpf-ci@kernel.org
To: vineet.gupta@linux.dev,ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com
Cc: martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,john.fastabend@gmail.com,shuah@kernel.org,bpf@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,vineet.gupta@linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 07/13] bpf: track low-32 scalar equality across sign-extending movs
Date: Thu, 10 Sep 2026 17:52:18 +0000 (UTC) [thread overview]
Message-ID: <654adc93a03b1bbeef530ffb6adb9a2d204e5bb01d7707dc0b16889fb05fc3dd@mail.kernel.org> (raw)
In-Reply-To: <20260910164635.459558-8-vineet.gupta@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 4189 bytes --]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index eb093194e2a3..308ff53232f0 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -16248,12 +16258,23 @@ static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)
> return -EACCES;
> } else if (src_reg->type == SCALAR_VALUE) {
> bool no_sext;
> + /*
> + * A 32-bit sign extension keeps the low 32
> + * bits, so record a low-32 link as the
> + * zero-extending mov does. A self-mov
> + * qualifies only if src is already linked.
> + */
> + bool subreg_link = (insn->off >> 3) == 4 &&
> + (src_reg != dst_reg ||
> + src_reg->id);
>
> no_sext = reg_umax(src_reg) < (1ULL << (insn->off - 1));
> - if (no_sext)
> + if (no_sext || subreg_link)
> assign_scalar_id_before_mov(env, src_reg);
^^^^
Can widening this guard drop an existing ADD_CONST link on the source
register? With 'no_sext || subreg_link', assign_scalar_id_before_mov() now
also runs on src_reg when !no_sext, and that helper discards the source's
delta tracking:
kernel/bpf/verifier.c:assign_scalar_id_before_mov() {
...
if (src_reg->add_const)
clear_scalar_id(src_reg);
if (!src_reg->id && !tnum_is_const(src_reg->var_off))
src_reg->id = ++env->id_gen;
...
}
clear_scalar_id() zeroes id, delta, add_const and subreg, and the following
statement then mints a brand-new id, so src_reg is unlinked from the
register set it was tracking. Before this commit the !no_sext arm left
src_reg untouched.
For a BPF_ALU64 | BPF_MOV | BPF_X with insn->off == 32:
r1 = r2 /* r1, r2 share id N */
r1 += 8 /* r1->add_const = ADD_CONST_64, r1->delta = 8 */
r3 = (s32)r1 /* r1 is wide -> !no_sext, subreg_link true */
if r2 < 100 goto out /* sync_linked_regs() no longer reaches r1 */
... use r1 ...
At the mov, r1 loses its ADD_CONST_64 / delta = 8 link and gets a fresh id,
so the following 'if r2 < 100' compare no longer refines r1 to [8, 107].
Is that the intent? This is the compiler idiom described in the comment
above adjust_reg_min_max_vals()'s delta handling.
The clear also does not look necessary for the new link: since !no_sext, the
SUBREG_SEXT link is established through the freshly minted id.
Would excluding add_const sources be enough, something like:
bool subreg_link = (insn->off >> 3) == 4 && !src_reg->add_const &&
(src_reg != dst_reg || src_reg->id);
The zero-extending arm added earlier in the series uses the same guard
shape, so a fix likely wants to cover both. Looking forward through
2c5433cf9fbb..1d3c4a0831be, the later commits extend the same mechanism to
narrowing stack fills and spills and reuse the identical guard, so none of
them change this.
> *dst_reg = *src_reg;
> - if (!no_sext)
> + if (!no_sext && subreg_link && src_reg->id)
> + dst_reg->subreg = SUBREG_SEXT;
^^^^
On a related note, for 'r0 = (s32)r0' where r0 carries add_const,
subreg_link is evaluated before the clear and sees the old src_reg->id as
non-zero, so it is true. assign_scalar_id_before_mov() then clears and
re-mints the id, and SUBREG_SEXT is applied to a register that is the sole
holder of that id.
The changelog says:
> Unlike the zero-extending arm, a self-mov can form a link here, but only
> when src is already linked: r0 = (s32)r0 is how a sign-extended int return
> lands. On an unlinked register there is nothing to link to, and minting an
> id would leave the register describing itself.
bpf_clear_singular_ids() drops singleton ids before state comparison, so
this does not look unsound, but does it match the rationale above?
> + else if (!no_sext)
> clear_scalar_id(dst_reg);
> coerce_reg_to_size_sx(dst_reg, insn->off >> 3);
> } else {
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/34506184282
next prev parent reply other threads:[~2026-09-10 17:52 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 16:46 [PATCH bpf-next v2 00/13] bpf: track scalar equality across the low 32 bits Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 01/13] bpf: move linked-scalar flags out of bpf_reg_state->id [NFC] Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci
2026-09-14 18:02 ` Vineet Gupta
2026-09-16 21:03 ` Alexei Starovoitov
2026-09-16 21:21 ` Vineet Gupta
2026-09-18 23:38 ` Vineet Gupta
2026-09-12 18:50 ` Alexei Starovoitov
2026-09-15 1:17 ` Vineet Gupta
2026-09-16 21:02 ` Alexei Starovoitov
2026-09-16 21:24 ` Vineet Gupta
2026-09-17 0:36 ` Alexei Starovoitov
2026-10-02 8:03 ` Vineet Gupta
2026-10-02 11:23 ` Alexei Starovoitov
2026-09-18 23:13 ` Eduard Zingerman
2026-09-21 18:44 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 02/13] bpf: compare linked-scalar kinds in regs_exact() Vineet Gupta
2026-09-12 18:51 ` Alexei Starovoitov
2026-09-15 1:11 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 03/13] bpf: track low-32 scalar equality across zero-extending movs Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci
2026-09-11 9:29 ` Vineet Gupta
2026-09-12 18:59 ` Alexei Starovoitov
2026-09-15 20:31 ` Vineet Gupta
2026-09-16 4:23 ` Alexei Starovoitov
2026-09-17 0:08 ` Vineet Gupta
2026-09-17 0:30 ` Alexei Starovoitov
2026-09-21 17:28 ` Eduard Zingerman
2026-09-21 18:59 ` Alexei Starovoitov
2026-09-21 19:10 ` Eduard Zingerman
2026-09-21 19:27 ` Alexei Starovoitov
2026-09-21 19:44 ` Eduard Zingerman
2026-09-21 21:55 ` Alexei Starovoitov
2026-09-21 22:17 ` Eduard Zingerman
2026-09-21 22:25 ` Alexei Starovoitov
2026-10-02 13:59 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 04/13] selftests/bpf: cover the low-32 link for " Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 05/13] bpf: keep the range across a sign extension that cannot change it Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci
2026-09-11 10:37 ` Vineet Gupta
2026-09-12 19:02 ` Alexei Starovoitov
2026-09-15 21:18 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 06/13] selftests/bpf: cover sign extensions that cannot change the range Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 07/13] bpf: track low-32 scalar equality across sign-extending movs Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci [this message]
2026-09-11 10:00 ` Vineet Gupta
2026-09-12 19:09 ` Alexei Starovoitov
2026-09-15 20:39 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 08/13] selftests/bpf: cover the low-32 link for " Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci
2026-09-11 8:00 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 09/13] bpf: track low-32 scalar equality across narrowing stack fills Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 10/13] selftests/bpf: cover the low-32 link for " Vineet Gupta
2026-09-10 17:31 ` bot+bpf-ci
2026-09-11 5:07 ` Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 11/13] bpf: record what a narrowing spill actually stores Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 12/13] bpf: track low-32 scalar equality across narrowing stack spills Vineet Gupta
2026-09-10 16:46 ` [PATCH bpf-next v2 13/13] selftests/bpf: cover the low-32 link for " Vineet Gupta
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=654adc93a03b1bbeef530ffb6adb9a2d204e5bb01d7707dc0b16889fb05fc3dd@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=vineet.gupta@linux.dev \
--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®