bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Borkmann" <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 3/6] bpf, x86: Fix exception table metadata for arena load-acquire
Date: Thu, 06 Aug 2026 20:30:31 +0000	[thread overview]
Message-ID: <20260806203032.09BEA1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260806201047.333389-3-daniel@iogearbox.net>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The x86 JIT exception table metadata fix for `BPF_PROBE_ATOMIC` successfully addresses `BPF_LOAD_ACQ` but incorrectly handles read-modify-write (RMW) fetch operations (e.g., `BPF_CMPXCHG`, `BPF_XCHG`, `BPF_ADD | BPF_FETCH`), leading to silent lock acquisition successes and potential information leaks.
- [High] The ARM64 and s390 BPF JITs fail to properly populate exception table metadata for arena atomic instructions, leaving both `BPF_LOAD_ACQ` (on ARM64) and RMW fetch atomics (on both architectures) broken on unmapped page faults.
--

--- Patch [3]: [PATCH bpf-next v2 3/6] bpf, x86: Fix exception table metadata for arena load-acquire ---
commit 45e0ae10aa75994903c64f22211117edeb408932
Author: Daniel Borkmann <daniel@iogearbox.net>

bpf, x86: Fix exception table metadata for arena load-acquire

This commit fixes an issue where load-acquire instructions on arena
pointers were incorrectly treated as stores by the exception table
logic on x86. It ensures the destination register is properly cleared
and the correct address register is reported during a fault.

> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index 01e7ce569c1ed..88ed95b2eaa72 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -2331,8 +2331,13 @@ st:			insn_off = insn->off;
>  				 * BPF_PROBE_ATOMIC) before being used for the memory access. Pass
>  				 * the reg holding the unmodified 32-bit address to
>  				 * ex_handler_bpf().
> +				 *
> +				 * A load-acquire is of BPF_STX class, but reads from src_reg
> +				 * into dst_reg like a BPF_LDX does, hence it must not be
> +				 * treated as a store here.
>  				 */
> -				if (BPF_CLASS(insn->code) == BPF_LDX) {
> +				if (BPF_CLASS(insn->code) == BPF_LDX ||
> +				    bpf_atomic_is_load_acq(insn)) {
>  					arena_reg = reg2pt_regs[src_reg];
>  					fixup_reg = reg2pt_regs[dst_reg];
>  				} else {
>  					arena_reg = reg2pt_regs[dst_reg];
>  					fixup_reg = DONT_CLEAR;
>  				}

[Severity: High]
This isn't a bug introduced by this patch, but it seems read-modify-write
(RMW) fetch operations like BPF_CMPXCHG, BPF_XCHG, and BPF_ADD | BPF_FETCH
might also be incorrectly handled here.

Since RMW fetch atomics belong to the BPF_STX class and are not LOAD_ACQ,
they incorrectly fall into this else branch in do_jit() where fixup_reg is
set to DONT_CLEAR.

If a BPF program executes a BPF_CMPXCHG on an unmapped arena page, the
exception handler will intercept the fault but leave the destination register
uncleared.

Could this allow a lock acquisition loop checking if the register matches the
expected value to falsely assume the lock was acquired, potentially bypassing
BPF concurrency controls?

Does this also risk leaking the uncleared pointer?


[Severity: High]
This is a pre-existing issue, but similar logic appears to be missing for
ARM64 and s390 JIT implementations for arena atomic instructions.

In arch/arm64/net/bpf_jit_comp.c:add_exception_handler():

	if (BPF_CLASS(insn->code) != BPF_LDX)
		dst_reg = DONT_CLEAR;

Does ARM64 also fail to identify BPF_LOAD_ACQ and RMW atomics as instructions
that require clearing a destination register, treating them as DONT_CLEAR?

This could trigger the exact same bug fixed for x86 in this patch.

Additionally, in arch/s390/net/bpf_jit_comp.c:bpf_jit_probe_atomic_pre():

	if (BPF_MODE(insn->code) != BPF_PROBE_ATOMIC)
		return;

For RMW atomics on s390, the function seems to fail to assign a register to be
cleared, meaning the exception handler does not clear any register upon an
unmapped page fault.

Could this also lead to silent lock acquisition bypass on s390?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806201047.333389-1-daniel@iogearbox.net?part=3

  reply	other threads:[~2026-08-06 20:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 20:10 [PATCH bpf-next v2 1/6] bpf: Reject load-acquire from pointers requiring fault protection Daniel Borkmann
2026-08-06 20:10 ` [PATCH bpf-next v2 2/6] bpf, riscv: Add and use bpf_atomic_is_load_acq() helper Daniel Borkmann
2026-08-06 20:10 ` [PATCH bpf-next v2 3/6] bpf, x86: Fix exception table metadata for arena load-acquire Daniel Borkmann
2026-08-06 20:30   ` sashiko-bot [this message]
2026-08-06 20:10 ` [PATCH bpf-next v2 4/6] bpf, arm64: " Daniel Borkmann
2026-08-06 20:10 ` [PATCH bpf-next v2 5/6] selftests/bpf: Add arena fault test for load-acquire Daniel Borkmann
2026-08-06 20:10 ` [PATCH bpf-next v2 6/6] selftests/bpf: Add load-acquire test for probe-memory pointer types Daniel Borkmann
2026-08-06 20:41 ` [PATCH bpf-next v2 1/6] bpf: Reject load-acquire from pointers requiring fault protection sashiko-bot
2026-08-07 13:00 ` 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=20260806203032.09BEA1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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;
as well as URLs for NNTP newsgroup(s).