BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Feng Jiang" <jiangfeng@kylinos.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4] bpf, riscv: fix extable handling for arena load_acquire
Date: Mon, 20 Jul 2026 07:06:18 +0000	[thread overview]
Message-ID: <20260720070619.41F2B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-bpf-riscv-fix-extable-v4-1-165c0b3b07d5@kylinos.cn>

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

Pre-existing issues:
- [High] The x86 BPF JIT incorrectly handles BPF_LOAD_ACQ instructions in its exception table population logic, leaving the destination register uncleared on an arena fault and checking the wrong register for arena violations.
--

--- Patch [1]: [PATCH v4] bpf, riscv: fix extable handling for arena load_acquire ---
commit 2540096dc96b56cd6aa635099890caa90920e4b4
Author: Feng Jiang <jiangfeng@kylinos.cn>

bpf, riscv: fix extable handling for arena load_acquire

This commit fixes the exception table handling for arena load_acquire
instructions in the RISC-V BPF JIT. It ensures that the destination register
is cleared on a fault to prevent verifier bypasses and pointer leaks.

Link: https://lore.kernel.org/r/20260720-bpf-riscv-fix-extable-v3-1-e9a603882309@kylinos.cn
Link: https://lore.kernel.org/r/20260716-bpf-riscv-fix-extable-v2-1-421f75812533@kylinos.cn
Link: https://lore.kernel.org/r/20260716-bpf-riscv-fix-extable-v1-1-af023cc17af4@kylinos.cn

> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index f9d5347ba966b..e1519ab4356c1 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -1986,7 +1986,12 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
>  		else
>  			ret = emit_atomic_rmw(rd, rs, insn, ctx);
>  
> -		ret = ret ?: add_exception_handler(insn, REG_DONT_CLEAR_MARKER, ctx);
> +		/* ret can be 1 (skip-zext); extable entry still needs to be added */
> +		if (ret >= 0)
> +			ret = add_exception_handler(insn,
> +				insn->imm == BPF_LOAD_ACQ ? rd : REG_DONT_CLEAR_MARKER,
> +				ctx) ?: ret;
> +

[Severity: High]
This is a pre-existing issue, but does the x86 BPF JIT have the exact same
bug that needs fixing?

Looking at do_jit() in arch/x86/net/bpf_jit_comp.c:

				if (BPF_CLASS(insn->code) == BPF_LDX) {
					arena_reg = reg2pt_regs[src_reg];
					fixup_reg = reg2pt_regs[dst_reg];
				} else {
					arena_reg = reg2pt_regs[dst_reg];
					fixup_reg = DONT_CLEAR;
				}

Since BPF_LOAD_ACQ is encoded with the BPF_STX class, it falls into the else
branch, setting fixup_reg to DONT_CLEAR.

If a BPF program executes a BPF_LOAD_ACQ with an invalid pointer into the
arena memory, causing a page fault, does this leave the destination register
un-zeroed?

Could this bypass the verifier's assumption that it was overwritten by a safe
scalar, potentially leaking kernel pointers out to userspace?

>  		if (ret)
>  			return ret;
>  		break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-bpf-riscv-fix-extable-v4-1-165c0b3b07d5@kylinos.cn?part=1

      reply	other threads:[~2026-07-20  7:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  6:42 [PATCH v4] bpf, riscv: fix extable handling for arena load_acquire Feng Jiang
2026-07-20  7:06 ` sashiko-bot [this message]

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=20260720070619.41F2B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jiangfeng@kylinos.cn \
    --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