All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
To: <bot+bpf-ci@kernel.org>, <bpf@vger.kernel.org>
Cc: <ast@kernel.org>, <andrii@kernel.org>, <daniel@iogearbox.net>,
	<eddyz87@gmail.com>, <emil@etsalapatis.com>, <tj@kernel.org>,
	<kkd@meta.com>, <kernel-team@meta.com>, <martin.lau@kernel.org>,
	<yonghong.song@linux.dev>, <mason@kernel.org>,
	<ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf-next v2 13/18] bpf: Bound program stack use by a per-program limit
Date: Thu, 24 Sep 2026 11:56:28 +0200	[thread overview]
Message-ID: <DLNGGISVWINA.35D1HVUJZDY10@gmail.com> (raw)
In-Reply-To: <52c1223353ad134a1dae657457cd39cb67c3e3d8caeaef0b07d4498f92bb653a@mail.kernel.org>

On Thu Sep 24, 2026 at 11:13 AM CEST, bot+bpf-ci wrote:
>> diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c
>> index 2f52315d8bdd..de83736509a8 100644
>> --- a/kernel/bpf/liveness.c
>> +++ b/kernel/bpf/liveness.c
>> @@ -36,9 +36,9 @@ enum {
>>   * relative index @i is at &bits[(i * FM_MASK_CNT + kind) * words]. A
>>   * half-slot at or past @words * BITS_PER_LONG is never read by this frame,
>>   * hence never live. An instruction that may read the whole frame, such as a
>> - * call passing a frame pointer to another subprog, widens the array to
>> - * FRAME_MAX_WORDS, so that the read cannot lose half-slots to a later
>> - * widening.
>> + * call passing a frame pointer to another subprog, widens the array to the
>> + * program's stack budget, the deepest an accepted program can reach, so
>> + * that the read cannot lose half-slots to a later widening.
>>   */
>>  struct frame_masks {
>>  	u32 words;
>> @@ -264,12 +264,16 @@ static int mark_stack_write(struct func_instance *instance, u32 frame, u32 insn_
>>
>>  /*
>>   * Mark every half-slot of @frame as possibly read by @insn_idx. This widens
>> - * the masks to the maximum width: a full read recorded at a narrower width
>> - * would leave the bits added by a later widening clear and lose part of it.
>> + * the masks to the program's stack budget: a full read recorded at a narrower
>> + * width would leave the bits added by a later widening clear and lose part of
>> + * it, and an access past the budget is rejected by the main pass later, so no
>> + * widening of an accepted program goes further.
>>   */
>> -static int mark_stack_read_all(struct func_instance *instance, u32 frame, u32 insn_idx)
>> +static int mark_stack_read_all(struct bpf_verifier_env *env, struct func_instance *instance,
>> +			       u32 frame, u32 insn_idx)
>>  {
>> -	return mark_stack_read(instance, frame, insn_idx, 0, FRAME_HALF_SPIS - 1);
>> +	return mark_stack_read(instance, frame, insn_idx, 0,
>> +			       env->stack_limit / BPF_HALF_REG_SIZE - 1);
>>  }
>
> The new comment on mark_stack_read_all() says "an access past the budget
> is rejected by the main pass later, so no widening of an accepted program
> goes further." Can that claim hold in all cases?
>
> bpf_compute_subprog_arg_access() records accesses on every instruction
> the CFG can reach, but do_check() only explores feasible paths. In
> check_cond_jmp_op(), when is_branch_taken() returns 0 or 1, the other
> branch is pushed only if !env->bypass_spec_v1.
>
> For a privileged load, a branch that is provably dead but not
> constant-folded is never verified. Looking at something like this:
>
>     call bpf_get_prandom_u32
>     r0 &= 15
>     if r0 > 20 goto L
>     r0 = 0
>     exit
>   L:
>     *(u64 *)(r10 - 1024) = r0
>
> The program is accepted with stack_limit == 512. The liveness pass
> still calls mark_stack_write() for half-slots 254..255, and
> widen_frame_masks() grows that frame past the budget, to 4 words.
>
> There is no functional impact. widen_frame_masks() keeps all old bits,
> and liveness is only queried from __clean_func_state() for half-slots
> below 2 * allocated_stack / BPF_REG_SIZE. allocated_stack only grows
> through grow_stack_state() after check_stack_access_within_bounds() has
> enforced -env->stack_limit. So bits past the budget are never read,
> and a read-all up to stack_limit / BPF_HALF_REG_SIZE - 1 covers every
> half-slot the verifier can query.
>
> Could the comments state that invariant (verifier states never hold slots
> past env->stack_limit), rather than claiming that accepted programs never
> record accesses past the budget? As written, a later change could rely on
> masks never being wider than the budget, for example to size a buffer from
> stack_limit instead of FRAME_MAX_WORDS, and that would be unsafe.
>

Reworded for v3: the comment now states the invariant that verifier states never
hold slots past the budget, and notes that unreachable code may still widen the
masks harmlessly.

>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35976322553


  reply	other threads:[~2026-09-24  9:56 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  8:25 [PATCH bpf-next v2 00/18] Raise BPF program stack size to 2KiB Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 01/18] bpf: Add accessors for verifier stack slots Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 02/18] bpf: Widen the stack slot index in the jump history Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 03/18] bpf: Store linked registers in the jump history as an array Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 04/18] bpf: Track backtracking stack slots with bitmaps Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 05/18] bpf: Track scratched stack slots with a bitmap Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 06/18] bpf: Treat unknown-size stack reads as reaching the frame top Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 07/18] bpf: Size liveness stack masks by the stack each frame uses Kumar Kartikeya Dwivedi
2026-09-24 15:12   ` Alexei Starovoitov
2026-09-24  8:25 ` [PATCH bpf-next v2 08/18] bpf: Grow the verifier id scratch on demand Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:55     ` Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 09/18] selftests/bpf: Cover the tail call caller stack depth limit Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 10/18] selftests/bpf: Check that narrow stack stores define no slot Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 11/18] selftests/bpf: Check liveness merge of masks with different widths Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 12/18] bpf: Size the per-frame verifier structures for a 2 KiB stack Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:56     ` Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 13/18] bpf: Bound program stack use by a per-program limit Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:56     ` Kumar Kartikeya Dwivedi [this message]
2026-09-24  8:25 ` [PATCH bpf-next v2 14/18] selftests/bpf: Add load conditions on the program stack limit Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 15/18] selftests/bpf: Give the 512-byte stack boundary tests a 2 KiB twin Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:56     ` Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 16/18] bpf, x86: Allow programs 2 KiB of stack Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:57     ` Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 17/18] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-09-24  9:00   ` bot+bpf-ci
2026-09-24  9:57     ` Kumar Kartikeya Dwivedi
2026-09-24  8:25 ` [PATCH bpf-next v2 18/18] selftests/bpf: Test the 2 KiB stack budget Kumar Kartikeya Dwivedi
2026-09-24  9:13   ` bot+bpf-ci
2026-09-24  9:58     ` Kumar Kartikeya Dwivedi

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=DLNGGISVWINA.35D1HVUJZDY10@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bot+bpf-ci@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=mason@kernel.org \
    --cc=tj@kernel.org \
    --cc=yonghong.song@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.