BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/4] bpf: Keep the lowest offset of a stack pointer that moves up
Date: Thu, 03 Dec 2026 20:31:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-248635@kernel.org> (raw)
In-Reply-To: <20261203195823.4058490-2-alexei.starovoitov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: record_stack_access() and fill_from_stack() miss
  narrowed fills below V
--

commit a30553fe2082bb3349a0b621d201a327d7a706aa
Author: Alexei Starovoitov <ast@kernel.org>

bpf: Keep the lowest offset of a stack pointer that moves up

This commit adds a lower-bound level (off_cnt = -1) to the arg_track lattice
in kernel/bpf/liveness.c so stack pointers that move up past four offsets
restrict register fills to slots at or above the lowest seen offset.

> diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c
> index 93f8d16864965..628f6f2d407eb 100644
> --- a/kernel/bpf/liveness.c
> +++ b/kernel/bpf/liveness.c

[ ... ]

> @@ -1682,9 +1705,10 @@ static int record_stack_access(struct bpf_verifier_env *env,
>  
>  	if (!info.size)
>  		return 0;
> -	if (arg->off_cnt == 0) {
> +	if (arg->off_cnt <= 0) {
>  		if (info.may_read) {
> -			err = mark_stack_read_all(env, instance, frame, insn_idx, !info.bytes_only);
> +			err = mark_stack_read_all(env, instance, frame, insn_idx,
> +						  !info.bytes_only && !arg->off_cnt);
>  			if (err)
>  				return err;
>  		}
> @@ -1693,9 +1717,12 @@ static int record_stack_access(struct bpf_verifier_env *env,
>  			if (err)
>  				return err;
>  		}
> -		return 0;
> +		if (!arg->off_cnt)
> +			return 0;
> +		/* The main pass can widen the range below the bound. It finds bytes there. */
> +		info.size = U32_MAX;
>  	}
> -	for (i = 0; i < arg->off_cnt; i++) {
> +	for (i = 0; i < abs(arg->off_cnt); i++) {
>  		err = record_stack_access_off(instance, arg, i, info, frame, insn_idx);
>  		if (err)
>  			return err;

[Severity: Medium]
Can a widened stack pointer still perform a register fill below the lower
bound?

In a loop leftover, join_range() can widen a PTR_TO_STACK downward to
-BPF_MAX_VAR_OFF + 1, which stays within the comparison range of
is_branch_taken().

Comparing it for equality against another same-frame PTR_TO_STACK at a
constant offset below arg->off[0] lets is_scalar_branch_taken() ->
scalars_refine_cond_op() narrow var_off back to that constant, so
check_stack_read() dispatches to check_stack_read_fixed_off().

Because mark_stack_read_all() clears fill when arg->off_cnt < 0,
__clean_func_state() degrades a spilled pointer in that slot to STACK_MISC
under allow_ptr_leaks, causing a regression where valid programs fail
verification with -EACCES.

fill_from_stack() has the same issue for spilled PTR_TO_STACK values below
off[0]: skipping those slots leaves downstream accesses through the filled
pointer without FM_LIVE_BEFORE marks, so __clean_func_state() poisons the
target slot with STACK_POISON.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203195823.4058490-1-alexei.starovoitov@gmail.com?part=1

  reply	other threads:[~2026-12-03 20:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 19:58 [PATCH bpf-next 0/4] bpf: Keep fewer states apart because of pointers Alexei Starovoitov
2026-12-03 19:58 ` [PATCH bpf-next 1/4] bpf: Keep the lowest offset of a stack pointer that moves up Alexei Starovoitov
2026-12-03 20:31   ` sashiko-bot [this message]
2026-12-03 19:58 ` [PATCH bpf-next 2/4] bpf: Let bpf_dynptr_from_mem() take memory that nothing invalidates Alexei Starovoitov
2026-12-03 19:58 ` [PATCH bpf-next 3/4] bpf: Join pointers to values of two maps Alexei Starovoitov
2026-12-03 20:42   ` bot+bpf-ci
2026-12-03 19:58 ` [PATCH bpf-next 4/4] selftests/bpf: Test walks over the stack and joins of map values Alexei Starovoitov

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=sashiko-outbox-248635@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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