mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: jiayuan.chen@linux.dev,bpf@vger.kernel.org
Cc: jiayuan.chen@linux.dev,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,shuah@kernel.org,paul.chaignon@gmail.com,ameryhung@gmail.com,shung-hsi.yu@suse.com,danjwade95@gmail.com,kafai.wan@linux.dev,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf 2/2] selftests/bpf: Add reg-invariants test for speculative pointer arithmetic
Date: Wed, 19 Aug 2026 13:49:25 +0000 (UTC)	[thread overview]
Message-ID: <6f1ad36389faad6328320aa25b4e8b0ff7bac66913d11273ee1f6ce43dbbbfbf@mail.kernel.org> (raw)
In-Reply-To: <20260819125840.286434-2-jiayuan.chen@linux.dev>

[-- Attachment #1: Type: text/plain, Size: 2469 bytes --]

> diff --git a/tools/testing/selftests/bpf/progs/verifier_bounds.c b/tools/testing/selftests/bpf/progs/verifier_bounds.c
> index bc038ac2df98..91d4600aa677 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_bounds.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_bounds.c
> @@ -2267,6 +2267,47 @@ __naked void deduce64_from_32_wrapping_32bit(void)
>  	: __clobber_all);
>  }
>
> +/*
> + * Unprivileged variable pointer arithmetic on a PTR_TO_MAP_VALUE whose
> + * offset collapses to a constant. The Spectre-v1 speculative path snapshots
> + * the pointer while its r32 has just been blanked but its offset not yet
> + * synced; the following register move used to trip reg_bounds_sanity_check()
> + * ("const subreg tnum out of sync with range bounds"). With
> + * BPF_F_TEST_REG_INVARIANTS that violation turns into a load failure, so the
> + * unprivileged program must still load.
> + */

This isn't a bug, but would it read more clearly to say the base
PTR_TO_MAP_VALUE has a constant offset that the speculative snapshot
captures, rather than that the offset "collapses to a constant"? The
addend itself has to stay variable for sanitize_ptr_alu() to simulate the
path at all.

> +SEC("socket")
> +__success __success_unpriv
> +__flag(BPF_F_TEST_REG_INVARIANTS)
> +__naked void spec_ptr_alu_const_offset(void)
> +{
> +	asm volatile ("							\
> +	call %[bpf_ktime_get_ns];					\
> +	*(u64*)(r10 - 16) = r0;						\
> +	r1 = 0;								\
> +	*(u64*)(r10 - 8) = r1;						\
> +	r2 = r10;							\
> +	r2 += -8;							\
> +	r1 = %[map_hash_8b] ll;						\
> +	call %[bpf_map_lookup_elem];					\
> +	if r0 == 0 goto l0_%=;						\
> +	r1 = *(u64*)(r10 - 16);						\
> +	r2 = 0x40000000;						\
> +	if r1 > r2 goto l0_%=;						\
> +	if r1 s> 1 goto l0_%=;		/* r1 in [0, 1] */		\
> +	r0 += r1;			/* ptr += bounded scalar */	\
> +	r9 = r0;			/* used to trip the warning */	\
> +	*(u8*)(r0 + 0) = r1;						\
> +l0_%=:	r0 = 0;								\
> +	exit;								\
> +	"
> +	:
> +	: __imm(bpf_ktime_get_ns),
> +	  __imm(bpf_map_lookup_elem),
> +	  __imm_addr(map_hash_8b)
> +	: __clobber_all);
> +}
> +
>  /* Check that range_within() compares cnum ranges, not min/max projections. */
>  SEC("socket")
>  __failure __msg("div by zero")


---
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/32257333410

  reply	other threads:[~2026-08-19 13:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19 12:58 [PATCH bpf 1/2] bpf: fix REG INVARIANTS VIOLATION on " Jiayuan Chen
2026-08-19 12:58 ` [PATCH bpf 2/2] selftests/bpf: Add reg-invariants test for " Jiayuan Chen
2026-08-19 13:49   ` bot+bpf-ci [this message]
2026-08-20 18:26   ` Eduard Zingerman
2026-08-20 18:25 ` [PATCH bpf 1/2] bpf: fix REG INVARIANTS VIOLATION on " Eduard Zingerman
2026-08-20 18:45   ` Kumar Kartikeya Dwivedi
2026-08-20 18:50 ` patchwork-bot+netdevbpf

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=6f1ad36389faad6328320aa25b4e8b0ff7bac66913d11273ee1f6ce43dbbbfbf@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clm@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=danjwade95@gmail.com \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jiayuan.chen@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai.wan@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=paul.chaignon@gmail.com \
    --cc=shuah@kernel.org \
    --cc=shung-hsi.yu@suse.com \
    --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®