All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yiyang Chen" <chenyy23@mails.tsinghua.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v4 3/4] bpf: Propagate untrusted pointer state in commuted arithmetic
Date: Wed, 29 Jul 2026 15:35:36 +0000	[thread overview]
Message-ID: <20260729153536.F3E2E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260729-c3-035-public-bpf-v4-v4-3-8ee297e2346b@mails.tsinghua.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] sanitize_err prints the wrong register name for immediate operations (BPF_K) when R0 contains a pointer.
--

--- Patch [3]: [PATCH bpf v4 3/4] bpf: Propagate untrusted pointer state in commuted arithmetic ---
commit 74ae77e327bede792130d0bf76a485d3ad9ef6b4
Author: Yiyang Chen <chenyy23@mails.tsinghua.edu.cn>

bpf: Propagate untrusted pointer state in commuted arithmetic

This patch modifies the BPF verifier's pointer arithmetic logic by moving
the early return for untrusted PTR_TO_MEM accesses. Placing it after the
pointer state is fully propagated ensures that operations like scalar +=
untrusted_pointer correctly leave the destination register as a PTR_TO_MEM.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index cdb61fab84351..fdc5fbb1f78ca 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -13707,13 +13707,6 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
>  		return -EACCES;
>  	}
>  
> -	/*
> -	 * Accesses to untrusted PTR_TO_MEM are done through probe
> -	 * instructions, hence no need to track offsets.
> -	 */
> -	if (base_type(ptr_reg->type) == PTR_TO_MEM && (ptr_reg->type & PTR_UNTRUSTED))
> -		return 0;
> -
>  	switch (base_type(ptr_reg->type)) {
>  	case PTR_TO_CTX:
>  	case PTR_TO_MAP_VALUE:

[ ... ]

> @@ -13750,6 +13743,13 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
>  	if (dst_reg != ptr_reg)
>  		*dst_reg = *ptr_reg;
>  
> +	/*
> +	 * Accesses to untrusted PTR_TO_MEM are done through probe
> +	 * instructions, hence no need to track offsets.
> +	 */
> +	if (base_type(ptr_reg->type) == PTR_TO_MEM && (ptr_reg->type & PTR_UNTRUSTED))
> +		return 0;
> +
>  	if (!check_reg_sane_offset_scalar(env, off_reg, ptr_reg->type) ||
>  	    !check_reg_sane_offset_ptr(env, ptr_reg, ptr_reg->type))
>  		return -EINVAL;

[Severity: Medium]
Does sanitize_err() print the wrong register name for immediate operations
(BPF_K) when R0 contains a pointer?

When an immediate pointer arithmetic operation is rejected, sanitize_err()
is called downstream of this offset checking logic:

kernel/bpf/verifier.c:sanitize_err() {
    ...
    u32 dst = insn->dst_reg, src = insn->src_reg;
    ...
    case REASON_TYPE:
        verbose(env, "R%d has pointer with unsupported alu operation, %s\n",
                regs[src].type == SCALAR_VALUE ? dst : src, err);
}

For BPF_K operations, insn->src_reg is 0. If a pointer was previously placed
in R0, or if R0 is uninitialized, regs[0].type will not be SCALAR_VALUE.
The ternary operation will then incorrectly choose src (R0) instead of the
destination register, emitting a confusing diagnostic message.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729-c3-035-public-bpf-v4-v4-0-8ee297e2346b@mails.tsinghua.edu.cn?part=3

  reply	other threads:[~2026-07-29 15:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 15:18 [PATCH bpf v4 0/4] bpf: Preserve pointer state for commuted arithmetic Yiyang Chen via B4 Relay
2026-07-29 15:18 ` Yiyang Chen
2026-07-29 15:18 ` [PATCH bpf v4 1/4] bpf: simplify sanitize_err() signature Yiyang Chen via B4 Relay
2026-07-29 15:18   ` Yiyang Chen
2026-07-29 15:18 ` [PATCH bpf v4 2/4] bpf: Preserve pointer state for commuted arithmetic Yiyang Chen via B4 Relay
2026-07-29 15:18   ` Yiyang Chen
2026-07-29 15:18 ` [PATCH bpf v4 3/4] bpf: Propagate untrusted pointer state in " Yiyang Chen via B4 Relay
2026-07-29 15:18   ` Yiyang Chen
2026-07-29 15:35   ` sashiko-bot [this message]
2026-07-29 15:18 ` [PATCH bpf v4 4/4] selftests/bpf: Cover commuted pointer state propagation Yiyang Chen via B4 Relay
2026-07-29 15:18   ` Yiyang Chen

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=20260729153536.F3E2E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyy23@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.