All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nuoqi Gui" <gnq25@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpf: Reject scalar addition from untrusted memory
Date: Tue, 09 Jun 2026 15:10:18 +0000	[thread overview]
Message-ID: <20260609151019.678141F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609-f01-03-scalar-add-bpf-next-v1-1-e6212e274155@mails.tsinghua.edu.cn>

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

Pre-existing issues:
- [Critical] The patch only prevents `scalar += untrusted_ptr` (BPF_ADD) but fails to reject other ALU operations like `BPF_SUB`, `BPF_XOR`, and `BPF_MUL`. This allows attackers to trivially bypass the new check and trigger the exact same verifier type-confusion bug.
--

commit cfb0cd2267dc0023c68b5a917127e38cfcf1a758
Author: Nuoqi Gui <gnq25@mails.tsinghua.edu.cn>

bpf: Reject scalar addition from untrusted memory

This commit attempts to fix a verifier issue where an untrusted PTR_TO_MEM
is added to a scalar, which would previously return early and leave the
verifier state stale. It rejects the addition before the early return,
while leaving pointer += scalar handled by existing rules.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index c8d980fdd7099..c6b350f9585ae 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -14823,6 +14823,14 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
>  				 * This is legal, but we have to reverse our
>  				 * src/dest handling in computing the range
>  				 */
> +				if (opcode == BPF_ADD &&
> +				    base_type(src_reg->type) == PTR_TO_MEM &&
> +				    (src_reg->type & PTR_UNTRUSTED)) {
> +					verbose(env, "R%d tried to add from %s to scalar\n",
> +						insn->dst_reg,
> +						reg_type_str(env, src_reg->type));
> +					return -EACCES;
> +				}
>  				err = mark_chain_precision(env, insn->dst_reg);
>  				if (err)
>  					return err;

[Severity: Critical]
This isn't a bug introduced by this patch, but by restricting this check
explicitly to BPF_ADD, does this leave other ALU operations like BPF_SUB,
BPF_XOR, or BPF_MUL vulnerable to the same regression?

If an attacker uses BPF_SUB or BPF_XOR (e.g., scalar ^= untrusted_ptr),
the new check is bypassed. The code then falls through to calling
adjust_ptr_min_max_vals(), where it hits an early return for untrusted
PTR_TO_MEM:

kernel/bpf/verifier.c:adjust_ptr_min_max_vals() {
    ...
    if (base_type(ptr_reg->type) == PTR_TO_MEM && (ptr_reg->type & PTR_UNTRUSTED))
        return 0;
    ...
}

This early return skips the validation block that would normally reject these
unsupported operations on pointers. This accepts the instruction without
updating the scalar's verifier bounds state, while its actual runtime value
is manipulated by the pointer.

Can this verifier state desynchronization be leveraged to achieve
out-of-bounds access?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260609-f01-03-scalar-add-bpf-next-v1-0-e6212e274155@mails.tsinghua.edu.cn?part=1

  reply	other threads:[~2026-06-09 15:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 14:55 [PATCH bpf-next 0/2] bpf: Reject scalar addition from untrusted memory Nuoqi Gui
2026-06-09 14:55 ` [PATCH bpf-next 1/2] " Nuoqi Gui
2026-06-09 15:10   ` sashiko-bot [this message]
2026-06-09 15:28   ` bot+bpf-ci
2026-06-09 17:01   ` Eduard Zingerman
2026-06-09 18:21     ` Emil Tsalapatis
2026-06-09 14:55 ` [PATCH bpf-next 2/2] selftests/bpf: Cover scalar addition from rdonly " Nuoqi Gui
2026-06-09 15:08   ` sashiko-bot

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=20260609151019.678141F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=gnq25@mails.tsinghua.edu.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 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.