All of lore.kernel.org
 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 1/6] bpf: Reject load-acquire from pointers requiring fault protection
Date: Thu, 06 Aug 2026 20:41:19 +0000	[thread overview]
Message-ID: <20260806204121.BCFA51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806201047.333389-1-daniel@iogearbox.net>

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

Pre-existing issues:
- [High] A pre-existing flaw allows merged untrusted pointer types to bypass BPF_PROBE_MEM rewriting for plain BPF_LDX instructions, leading to kernel panics upon NULL pointer dereference.
--

--- Patch [1]: [PATCH bpf-next v2 1/6] bpf: Reject load-acquire from pointers requiring fault protection ---
commit e15f6fca389dca527ccadeba23f22ab6d2f2f36d
Author: Daniel Borkmann <daniel@iogearbox.net>

bpf: Reject load-acquire from pointers requiring fault protection

This commit prevents BPF_LOAD_ACQ instructions from using pointer types that
would normally require fault protection (like untrusted pointers or bare
PTR_TO_BTF_ID). Since BPF_LOAD_ACQ is not rewritten to use BPF_PROBE_MEM
by the verifier, a fault from these pointers would panic the kernel
instead of being safely handled. The fix explicitly rejects these unsafe
source pointer types for load-acquires.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index e6233c0081d10..648c5784178ec 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -4923,6 +4923,30 @@ static bool is_arena_reg(struct bpf_verifier_env *env, int regno)
>  	return reg->type == PTR_TO_ARENA;
>  }
>  
> +static bool is_load_acq_unsafe(struct bpf_verifier_env *env, int regno,
> +			       struct bpf_insn *insn)
> +{
> +	const struct bpf_reg_state *reg = reg_state(env, regno);
> +
> +	/*
> +	 * A BPF_LOAD_ACQ is not rewritten to a BPF_PROBE_MEM load by the
> +	 * verifier, unlike a regular BPF_LDX. The JIT would emit a plain load
> +	 * with no exception table entry, so a fault (e.g. NULL deref) crashes
> +	 * the kernel instead of being handled.
> +	 *
> +	 * Reject the source pointer types that a BPF_LDX would have had that
> +	 * fault protection applied to, i.e. the ones bpf_convert_ctx_accesses()
> +	 * turns into BPF_PROBE_MEM: a bare PTR_TO_BTF_ID and any PTR_UNTRUSTED
> +	 * pointer (untrusted btf ids, untrusted MEM_ALLOC, rdonly untrusted
> +	 * memory). A PTR_TRUSTED pointer is not among them, is not converted,
> +	 * and stays allowed. Same for the other flagged PTR_TO_BTF_ID variants
> +	 * (MEM_ALLOC, MEM_RCU, ...), hence the exact match on the base type.
> +	 */

[Severity: High]
This is a pre-existing issue, but does bpf_convert_ctx_accesses() actually
rewrite all PTR_UNTRUSTED pointers as the comment suggests?

It appears that if control flow paths merge at a BPF_LDX instruction,
save_aux_ptr_type() in kernel/bpf/verifier.c merges their pointer types:

    if (type & PTR_UNTRUSTED || *prev_type & PTR_UNTRUSTED)
        merged_type |= PTR_UNTRUSTED;
    if ((type & MEM_RDONLY) || (*prev_type & MEM_RDONLY))
        merged_type |= MEM_RDONLY;
    *prev_type = merged_type;

If one path uses a valid memory pointer like PTR_TO_MEM and the other uses
an untrusted pointer like PTR_TO_BTF_ID | PTR_UNTRUSTED, they merge into
PTR_TO_MEM | PTR_UNTRUSTED without the MEM_RDONLY flag.

However, looking at bpf_convert_ctx_accesses() in kernel/bpf/fixups.c:

    case PTR_TO_BTF_ID | MEM_ALLOC | PTR_UNTRUSTED:
    case PTR_TO_MEM | MEM_RDONLY | PTR_UNTRUSTED:
        if (type == BPF_READ) {
            if (BPF_MODE(insn->code) == BPF_MEM)

This switch statement doesn't have a case for PTR_TO_MEM | PTR_UNTRUSTED.
Could this allow a regular BPF_LDX instruction to bypass the BPF_PROBE_MEM
rewrite and cause a kernel panic if the untrusted pointer path is taken at
runtime and is NULL?

> +	return insn->imm == BPF_LOAD_ACQ &&
> +	       (reg->type == PTR_TO_BTF_ID ||
> +		(type_flag(reg->type) & PTR_UNTRUSTED));
> +}
> +

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

  parent reply	other threads:[~2026-08-06 20:41 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
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 ` sashiko-bot [this message]
2026-08-07 13:00 ` [PATCH bpf-next v2 1/6] bpf: Reject load-acquire from pointers requiring fault protection 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=20260806204121.BCFA51F000E9@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 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.