BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luis Gerhorst" <luis.gerhorst@fau.de>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 2/4] selftests/bpf: Test the insns that bpf_insert_insns() inserts
Date: Wed, 25 Nov 2026 17:39:44 +0000	[thread overview]
Message-ID: <sashiko-outbox-233852@kernel.org> (raw)
In-Reply-To: <009289699441bb2f2f7d05ade781e8644b23d04e.1795625597.git.luis.gerhorst@fau.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selftests/bpf: rnd_hi32_patch on w0 in
  zext_cmpxchg32_jump_out_of_range()
--

commit 05c2252db292a3024a0c209b16a5310701e3d6bb
Author: Luis Gerhorst <luis.gerhorst@fau.de>

selftests/bpf: Test the insns that bpf_insert_insns() inserts

This commit adds BPF verifier selftests covering upper-32-bit randomization
under BPF_F_TEST_RND_HI32 and jump range overflow when inserting zext or
per-CPU address instructions via bpf_insert_insns().

> diff --git a/tools/testing/selftests/bpf/progs/verifier_zext.c b/tools/testing/selftests/bpf/progs/verifier_zext.c
> index 572017fe28fbe..d06a02242c555 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_zext.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_zext.c
> @@ -415,4 +415,61 @@ __naked void probe_mem(void)

[ ... ]

> +/*
> + * The zext is inserted behind the cmpxchg, between a jump with the smallest
> + * offset and its target. The program is valid, it is only rejected because the
> + * verifier can not widen a jump when it patches a program.
> + */
> +SEC("tc")
> +__description("zext does not fit behind a cmpxchg")
> +__failure __msg("cannot be patched due to 16-bit range")
> +__naked void zext_cmpxchg32_jump_out_of_range(void)
> +{
> +	asm volatile ("					\
> +	call %[bpf_get_prandom_u32];			\
> +	r6 = r0;					\
> +	r7 = 0;						\
> +	goto l1_%=;					\
> +l0_%=:	r0 = 0;						\
> +	exit;						\
> +l1_%=:	r1 = 0;						\
> +	*(u64 *)(r10 - 8) = r1;				\
> +	w0 = 0;						\
> +	w1 = 1;						\
> +	.8byte %[cmpxchg32];				\
> +	r2 = r0;					\
> +	.rept 32759;					\
> +	r1 = 0;						\
> +	.endr;						\
> +	if r7 != r6 goto l0_%=;				\
> +	r0 = r2;					\
> +	exit;						\
> +"	:
> +	: __imm(bpf_get_prandom_u32),
> +	  __imm_insn(cmpxchg32,
> +		     BPF_ATOMIC_OP(BPF_W, BPF_CMPXCHG, BPF_REG_10, BPF_REG_1, -8))
> +	: __clobber_all);
> +}

[Severity: Medium]
Does zext_cmpxchg32_jump_out_of_range() fail while patching w0 = 0 with
rnd_hi32_patch instead of reaching cmpxchg32 to test zext_patch?

test_loader sets BPF_F_TEST_RND_HI32 by default via testing_prog_flags().
Because the 32-bit BPF_CMPXCHG only reads the low 32 bits of r0 and r1, the
upper 32 bits of w0 = 0 (insn 8) and w1 = 1 (insn 9) are dead
(zext_dst == false).  When bpf_opt_subreg_zext_lo32_rnd_hi32() iterates
forward through the program, it visits w0 = 0 first and inserts
rnd_hi32_patch there, which fails with "insn 8 cannot be patched due to
16-bit range" and aborts before reaching cmpxchg32 at insn 10.  Because
__msg("cannot be patched due to 16-bit range") omits the instruction index,
the test passes without exercising the zext_patch insertion path.

Using 64-bit moves (r0 = 0 and r1 = 1) and matching "insn 10 cannot be
patched due to 16-bit range" would ensure the failure happens on the
zext_patch insertion after cmpxchg32.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795625597.git.luis.gerhorst@fau.de?part=2

  reply	other threads:[~2026-11-25 17:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  4:08 [PATCH bpf 0/5] bpf: Fixes for speculation barriers and constant reads Alexei Starovoitov
2026-11-25  4:08 ` [PATCH bpf 1/5] bpf: Undo insn aux changes of a failed speculative path Alexei Starovoitov
2026-11-25  4:08 ` [PATCH bpf 2/5] bpf: Treat NOT_INIT as a pointer in __is_pointer_value() Alexei Starovoitov
2026-11-25  4:08 ` [PATCH bpf 3/5] bpf: Use get_unaligned() in bpf_map_direct_read() Alexei Starovoitov
2026-11-25  4:08 ` [PATCH bpf 4/5] bpf: Emit nospec after BPF_ATOMIC stores to the stack Alexei Starovoitov
2026-11-25 17:12   ` Luis Gerhorst
2026-11-25 17:12     ` [PATCH bpf 0/4] bpf: Emit nospec after every insn that " Luis Gerhorst
2026-11-25 17:12       ` [PATCH bpf 1/4] bpf: Add bpf_insert_insns() to insert insns next to an insn Luis Gerhorst
2026-11-25 17:51         ` sashiko-bot
2026-11-25 18:17         ` bot+bpf-ci
2026-11-25 17:12       ` [PATCH bpf 2/4] selftests/bpf: Test the insns that bpf_insert_insns() inserts Luis Gerhorst
2026-11-25 17:39         ` sashiko-bot [this message]
2026-11-25 17:12       ` [PATCH bpf 3/4] bpf: Emit nospec after every insn with nospec_result Luis Gerhorst
2026-11-25 18:17         ` bot+bpf-ci
2026-11-25 17:12       ` [PATCH bpf 4/4] selftests/bpf: Test nospec after stack writes of calls and atomics Luis Gerhorst
2026-11-25 17:45         ` sashiko-bot
2026-11-26  3:40     ` [PATCH bpf 4/5] bpf: Emit nospec after BPF_ATOMIC stores to the stack Alexei Starovoitov
2026-11-25  4:08 ` [PATCH bpf 5/5] bpf: Do not end a speculative path at a call Alexei Starovoitov
2026-11-25  5:00   ` bot+bpf-ci

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=sashiko-outbox-233852@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=luis.gerhorst@fau.de \
    --cc=sashiko-reviews@lists.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