From: sashiko-bot@kernel.org
To: "Vineet Gupta" <vineet.gupta@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 12/13] bpf: track low-32 scalar equality across narrowing stack spills
Date: Thu, 10 Sep 2026 17:05:59 +0000 [thread overview]
Message-ID: <20260910170600.0DFBA1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260910164635.459558-13-vineet.gupta@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Sign-extending loads from 32-bit narrowing spills incorrectly inherit and preserve a `SUBREG_ZEXT` link, causing a critical discrepancy between verifier bounds and runtime values.
--
commit 3396576ba1c56571ccd9a040716058594f558da8
Author: Vineet Gupta <vineet.gupta@linux.dev>
bpf: track low-32 scalar equality across narrowing stack spills
This commit allows the verifier to track a SUBREG_ZEXT relationship when a
64-bit scalar is narrowed during a 4-byte stack spill. This preserves the
knowledge of the lower 32 bits for subsequent loads.
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6cb35fc0d0fb0..9e63eddb9023b 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -3678,8 +3687,15 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env,
> * it came from.
> */
> coerce_reg_to_size(&state->stack[spi].spilled_ptr, size);
> - /* Break the relation on a narrowing spill. */
> - clear_scalar_id(&state->stack[spi].spilled_ptr);
> + if (subreg_link && reg->id)
> + state->stack[spi].spilled_ptr.subreg = SUBREG_ZEXT;
[Severity: Critical]
Can this lead to verifier state corruption when the spilled value is later
read with a 4-byte sign-extending load (BPF_MEMSX)?
If a BPF program performs 64-bit arithmetic to create an unknown scalar and
spills it to the stack via a 4-byte narrowing store, it records a SUBREG_ZEXT
link here and coerces its bounds to 32 bits.
If it then reads it back via a 4-byte sign-extending load, when processing
the read in check_stack_read_fixed_off(), narrowing evaluates to false since
the bounds were already truncated during the spill:
bool narrowing = get_reg_width(reg) > size * BITS_PER_BYTE;
As a result, subreg_link is false, and the verifier skips the
is_ldsx ? SUBREG_SEXT : SUBREG_ZEXT correction logic. The destination
register blindly inherits the stack slot's SUBREG_ZEXT link.
In check_mem_access(), coerce_reg_to_size_sx() properly sign-extends the
loaded value's bounds, but because the subreg link is non-zero, it skips
breaking the scalar ID:
if (!no_sext && !regs[value_regno].subreg)
clear_scalar_id(®s[value_regno]);
The register now has sign-extended bounds but a SUBREG_ZEXT link to the
original 64-bit scalar.
If the original scalar is later refined, sync_linked_regs() will invoke
reconstruct_zext32(), completely overwriting the sign-extended bounds with
zero-extended bounds. The verifier will incorrectly assume the register holds
a positive value, while at runtime it holds a negative sign-extended value.
Does this permit arbitrary out-of-bounds kernel memory accesses?
> + else
> + /*
> + * Nothing to relate: either the source has no
> + * id to share, or the store is narrower than
> + * the 32 bits a link can describe.
> + */
> + clear_scalar_id(&state->stack[spi].spilled_ptr);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910164635.459558-1-vineet.gupta@linux.dev?part=12
next prev parent reply other threads:[~2026-09-10 17:06 UTC|newest]
Thread overview: 39+ 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:00 ` sashiko-bot
2026-09-11 6:56 ` Vineet Gupta
2026-09-10 17:52 ` bot+bpf-ci
2026-09-12 18:50 ` Alexei Starovoitov
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-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-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:08 ` sashiko-bot
2026-09-10 17:52 ` bot+bpf-ci
2026-09-11 10:37 ` Vineet Gupta
2026-09-12 19:02 ` Alexei Starovoitov
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
2026-09-11 10:00 ` Vineet Gupta
2026-09-12 19:09 ` Alexei Starovoitov
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 17:04 ` sashiko-bot
2026-09-11 6:07 ` Vineet Gupta
2026-09-11 6:43 ` 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:00 ` sashiko-bot
2026-09-11 5:34 ` 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 17:05 ` sashiko-bot [this message]
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=20260910170600.0DFBA1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vineet.gupta@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