From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 24/73] bpf: Record what each call acquires and releases
Date: Tue, 01 Dec 2026 05:31:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-242601@kernel.org> (raw)
In-Reply-To: <e20a17a5d172179e6c13276b6fe9747e213a078a.1796099737.git.memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: under-counted note->held on NULL return in
bpf_pad_note_return()
--
commit 8812639e48841c61905030b2e860b98938bc3bc3
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Record what each call acquires and releases
This commit records in struct bpf_pad_note what each call instruction
acquires or releases during the main verification pass, preparing for
hidden stack slots that landing pads will use to release resources.
> diff --git a/kernel/bpf/pads.c b/kernel/bpf/pads.c
> index 5c0973e2e2411..657f17f2aaabb 100644
> --- a/kernel/bpf/pads.c
> +++ b/kernel/bpf/pads.c
[ ... ]
> @@ -1144,6 +1155,278 @@ struct bpf_pad_plan *bpf_pad_visit(struct bpf_verifier_env *env,
[ ... ]
> +void bpf_pad_note_return(struct bpf_verifier_env *env, const struct bpf_verifier_state *st,
> + const struct bpf_func_state *caller, int call_idx, bool plain)
> +{
> + const struct bpf_func_state *callee = st->frame[st->curframe];
> + const struct bpf_reference_state *ref = &st->refs[callee->entry_refs];
> + struct bpf_subprog_info *sub = &env->subprog_info[caller->subprogno];
> + struct bpf_insn_aux_data *aux = &env->insn_aux_data[call_idx];
> + const struct bpf_reg_state *r0 = &callee->regs[BPF_REG_0];
> + int i, nr = st->acquired_refs - callee->entry_refs, in_r0 = 0;
> + struct bpf_pad_place place;
> + struct bpf_pad_ent ent;
> +
> + for (i = 0; i < BPF_PAD_NR_SECTIONS; i++)
> + if (frame_sections(st, i))
> + sub->no_slots |= BIT(i);
> + if (plain && nr == 1 && ref->type == REF_TYPE_PTR && !ref->parent_id)
> + add_ref_cand(&place, &in_r0, r0, ref, BPF_PLACE_REG, BPF_REG_0);
> + if (in_r0 && slot_ent(env, &ent, st, ref, r0, true) &&
> + can_release_under_lock(env, st, caller, &ent)) {
> + note_acquire(env, sub, call_idx, &ent, BPF_REG_0,
> + count_refs(st, caller->entry_refs, callee->entry_refs,
> + BPF_PAD_GROUP_REFS));
> + } else {
> + for (i = 0; i < nr; i++)
> + sub->no_slots |= BIT(class_group(ref_class(&ref[i])));\
> + aux->call_brings_nothing |= plain && !reg_is_null(r0);
> + }
> + if (aux->call_brings_nothing && aux->pad_note && aux->pad_note->acquires)
> + sub->no_slots |= BIT(BPF_PAD_GROUP_REFS);
> +}
[Severity: Medium]
Can bpf_pad_note_return() leave aux->pad_note->held under-counted when a
subprogram returns NULL (nr == 0 and reg_is_null(r0)) while the caller
already holds references of BPF_PAD_GROUP_REFS?
When a subprogram called in a loop acquires and returns a reference on
trip 0 (while the caller holds 0 references) and returns NULL on a later
trip (while the caller still holds the reference from trip 0), the NULL
return takes the else branch with aux->call_brings_nothing remaining false
and never updates aux->pad_note->held with the caller's held count (or
checks it against BPF_PAD_MAX_ENTS). Once hidden slots are wired up in
commit "bpf: Add hidden stack slots for landing pads", the call is given
only 1 + note->held = 1 slot with an unconditional store of R0, so the
NULL return overwrites the active pointer in that slot with 0 and a
subsequent landing pad leaks the reference.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796099737.git.memxor@gmail.com?part=24
next prev parent reply other threads:[~2026-12-01 5:31 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 4:38 [PATCH bpf-next v1 00/73] Cancellations Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 01/73] bpf: Refuse a program that is too large for bpf_prog->pages Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 02/73] bpf: Require CAP_PERFMON for unwind_exit and unwind_goto Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 03/73] bpf: Reject bpf_percpu_obj_drop() of a type with special fields Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 04/73] bpf: Drop the edge after bpf_throw() from the control flow graph Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 05/73] bpf: Let a helper call its callback with an unwind label Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 06/73] bpf, x86, arm64: Add landings that redo what follows a helper call Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 07/73] bpf: Let a callback unwind out of a helper that has an unwind label Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 08/73] bpf: Let the inlined bpf_loop pass on a callback that unwinds Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 09/73] bpf: Give the helpers that call a callback an unwind label Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 10/73] bpf: Let the comparator of bpf_rbtree_add unwind Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 11/73] bpf: Let a state leave its frame at may_goto without an exit insn Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` sashiko-bot
2026-12-01 4:38 ` [PATCH bpf-next v1 12/73] bpf: Choose what a cancelled program returns by its type Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 13/73] bpf: Emit landing pads that leave RCU sections Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 14/73] bpf: Release locks and irq flags in landing pads Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 15/73] bpf: Add unwind_goto after calls of subprogs Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 16/73] bpf: Let the kernel cancel a program in a global subprog Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 17/73] bpf: Release references in landing pads Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 18/73] bpf: Release iterators and dynptrs " Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 19/73] bpf: Check pointers for NULL " Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 20/73] bpf: Let the kernel cancel a frame that holds references Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 21/73] bpf: Add unwind_goto after helpers with a callback Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 22/73] bpf: Let a may_goto that the verifier adds go to its landing pad only Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 23/73] bpf: Record why a callee is cancelled when its call gets no landing pad Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 24/73] bpf: Record what each call acquires and releases Kumar Kartikeya Dwivedi
2026-12-01 5:31 ` sashiko-bot [this message]
2026-12-01 4:38 ` [PATCH bpf-next v1 25/73] bpf: Add hidden stack slots for landing pads Kumar Kartikeya Dwivedi
2026-12-01 5:40 ` sashiko-bot
2026-12-01 4:38 ` [PATCH bpf-next v1 26/73] bpf: Use hidden slots for a pointer that has no location at a site Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 27/73] bpf: Restore the sections of the call when a frame is cancelled Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 28/73] bpf: Let hidden slots follow what a subprog does for its caller Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 29/73] bpf: Let a callee hold a reference that its call hands over Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 30/73] bpf: Let a call clear the hidden slot of what its callee releases Kumar Kartikeya Dwivedi
2026-12-01 4:38 ` [PATCH bpf-next v1 31/73] bpf: Give a callee a hidden slot for the reference that it is handed Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:38 ` [PATCH bpf-next v1 32/73] bpf: Give unwind_goto a 32 bit offset and prepare it for arena accesses Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 33/73] bpf, x86: Go to the landing pad when an access to arena faults Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 34/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 35/73] bpf: Let a register be the location of a lock in a global variable Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 36/73] bpf: Cancel a program at a fault in arena Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 37/73] bpf: Share one landing pad among accesses to arena where nothing is held Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 38/73] bpf: Keep R0, R6-R9 and the stack live at a call of bpf_throw() Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 39/73] bpf: Refuse freplace on a function that can unwind Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 40/73] bpf: Let landing pads pass on the value of unwind_exit Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 41/73] bpf: Keep a reference of the caller that a function finds NULL Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 42/73] bpf: Make bpf_throw() cancel the program through landing pads Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 43/73] bpf, x86: Remove the exception boundary Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 44/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 45/73] s390/bpf: " Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 46/73] powerpc64/bpf: " Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 47/73] bpf: Remove the stack walk of bpf_throw() Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 48/73] bpf: Find at a site that a frame holds more than a landing pad releases Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 49/73] bpf: Cancel the program when the time of its own may_goto is up Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 50/73] bpf: Reject a program that has no landing pad for a fault in arena Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 51/73] bpf: Log why a call is a site and which functions cannot be cancelled Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 52/73] bpf: Add cancel_goto and cancel_exit, which only the verifier emits Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 53/73] bpf: Give the unwind label of a helper a second way in Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 54/73] bpf, x86: Put the landing of unwind_goto after the function Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 55/73] bpf, x86: Return to cancel_goto at cancel_exit Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 56/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 57/73] bpf: Use cancel_exit to leave a frame that the kernel cancels Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 58/73] bpf: Check that a helper whose callback may unwind has an unwind label Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 59/73] bpf: Find the landing pads of a program that can only clean up Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 60/73] bpf: Don't let hidden stack words turn on the private stack Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 61/73] bpf: Add a landing pad per site for frames that are cancelled already Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 62/73] bpf: Verify a cleanup pad for a frame that is cancelled Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 63/73] bpf: Reject a program whose cleanup pad a cancellation cannot enter Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 64/73] bpf: Find the code that a cleanup pad can reach Kumar Kartikeya Dwivedi
2026-12-01 5:41 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 65/73] bpf: Emit the stub, the entry and the remainder of a cleanup pad Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 66/73] bpf: Let the entry of a cleanup pad save the pointers of the frame Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 67/73] bpf: Run the cleanup pads of a program when the kernel cancels it Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 68/73] bpf: End the path at a call of a global subprog that never returns Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 69/73] bpf: Tell struct_ops when a program was cancelled Kumar Kartikeya Dwivedi
2026-12-01 5:26 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 70/73] bpf: Tell struct_ops when cancel_exit returns to the kernel Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 71/73] bpf: Let a struct_ops say what a cancelled program returns Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
2026-12-01 4:39 ` [PATCH bpf-next v1 72/73] bpf: Give cancelled tcp_congestion_ops programs values that TCP can take Kumar Kartikeya Dwivedi
2026-12-01 4:39 ` [PATCH bpf-next v1 73/73] sched_ext: Treat a cancelled program as a scheduler error Kumar Kartikeya Dwivedi
2026-12-01 5:25 ` bot+bpf-ci
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-242601@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--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