All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emil Tsalapatis" <emil@etsalapatis.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf 08/11] selftests/bpf: Test for mixed arena/nonarena code paths
Date: Wed, 16 Sep 2026 05:17:56 +0000	[thread overview]
Message-ID: <20260916051757.0C0DC1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916050830.8774-9-emil@etsalapatis.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: verifier tests for mixed-type CFG paths are vulnerable to compiler optimizations
--

commit 2865d7b4af7e52310b9ec10118abb32164639af3
Author: Emil Tsalapatis <emil@etsalapatis.com>

selftests/bpf: Test for mixed arena/nonarena code paths

Add a selftest to confirm the verifier rejects ALU operations
that return arena or non-arena results depending on code path.

> diff --git a/tools/testing/selftests/bpf/progs/verifier_arena.c b/tools/testing/selftests/bpf/progs/verifier_arena.c
> index 332322c9b54cf..1ce9c4b784816 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_arena.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_arena.c
> @@ -561,6 +561,55 @@ int arena_ptr_add_arena_ptr(void *ctx)
>  	return 0;
>  }
>  
> +SEC("syscall")
> +__failure __msg("same insn cannot be used with and without arena pointer")
> +int mixed_arena_scalar_alu64_scalar_first(void *ctx)
> +{
> +	volatile register __u64 reg asm("r3");
> +	__u32 pick_arena = bpf_get_prandom_u32();
> +
> +	reg = 1ULL << 32;
> +
> +	if (pick_arena) {
> +		asm volatile (
> +			"r9 = %[arena] ll;"
> +			"%[reg] = 0;"
> +			"%[reg] = addr_space_cast(%[reg], 0x0, 0x1);"
> +			: [reg] "=r"(reg)
> +			: __imm_addr(arena)
> +			: "r9"
> +		);
> +	}
> +
> +	reg += 1;
> +
> +	return 0;

[Severity: Medium]
Are these tests vulnerable to compiler optimizations?

Since these tests rely on the control flow converging to evaluate a single
instruction with mixed types (SCALAR_VALUE and PTR_TO_ARENA), could compiler
optimizations like Clang's tail duplication duplicate the reg += 1; return 0;
block into both branches?

If the tail block is duplicated, the verifier would evaluate two separate
addition instructions, each with a uniform type, bypassing the mixed-type
check entirely and causing the test to fail to produce the expected
__failure __msg(...).

Should these functions be written using __naked and explicit assembly (like
mixed_arena_stack_atomic) to guarantee the exact instruction sharing
required for this test?

> +}
> +
> +SEC("syscall")
> +__failure __msg("same insn cannot be used with and without arena pointer")
> +int mixed_arena_scalar_alu64_arena_first(void *ctx)
> +{
> +	volatile register __u64 reg asm("r3");
> +	__u32 pick_scalar = bpf_get_prandom_u32();
> +
> +	asm volatile (
> +		"r9 = %[arena] ll;"
> +		"%[reg] = 0;"
> +		"%[reg] = addr_space_cast(%[reg], 0x0, 0x1);"
> +		: [reg] "=r"(reg)
> +		: __imm_addr(arena)
> +		: "r9"
> +	);
> +
> +	if (pick_scalar)
> +		reg = 1ULL << 32;
> +
> +	reg += 1;
> +
> +	return 0;

[Severity: Medium]
Similarly, could the tail addition here be duplicated into both execution
paths by the compiler, invalidating the test's mixed-type validation logic?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916050830.8774-1-emil@etsalapatis.com?part=8

  reply	other threads:[~2026-09-16  5:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  5:08 [PATCH bpf 00/11] skb/arena bugfixes Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 01/11] bpf: Fix bounds check for skb-backed dynptrs Emil Tsalapatis
2026-09-16 11:52   ` Jiayuan Chen
2026-09-16 23:08   ` Jakub Kicinski
2026-09-16  5:08 ` [PATCH bpf 02/11] selftests/bpf: Test dynptr slices past end of skb Emil Tsalapatis
2026-09-16  5:18   ` sashiko-bot
2026-09-16  5:08 ` [PATCH bpf 03/11] bpf: Fix bpf_sock context code generation Emil Tsalapatis
2026-09-16 12:21   ` Jiayuan Chen
2026-09-16  5:08 ` [PATCH bpf 04/11] selftests/bpf: Add selftests for rx_queue_mapping context access Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 05/11] bpf: Reject pkt arguments in mutating subprogs Emil Tsalapatis
2026-09-16  5:57   ` Amery Hung
2026-09-16  5:58     ` Amery Hung
2026-09-16 18:41     ` Emil Tsalapatis
2026-09-16 19:26       ` Amery Hung
2026-09-16  5:08 ` [PATCH bpf 06/11] selftests/bpf: Test rejection of pkt args to " Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 07/11] bpf: Prevent variable arena/non-arena register contents Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 08/11] selftests/bpf: Test for mixed arena/nonarena code paths Emil Tsalapatis
2026-09-16  5:17   ` sashiko-bot [this message]
2026-09-16  5:08 ` [PATCH bpf 09/11] bpf: Track whether dynptr type is known Emil Tsalapatis
2026-09-16  5:22   ` sashiko-bot
2026-09-16 18:41     ` Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 10/11] bpf: Track skb memory invalidation by packet-backed dynptrs Emil Tsalapatis
2026-09-16  5:08 ` [PATCH bpf 11/11] selftests/bpf: Test dynptr slice invalidation on skb clobber Emil Tsalapatis

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=20260916051757.0C0DC1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=emil@etsalapatis.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.