From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 12/29] bpf: Release resources in hidden slots on bpf_throw()
Date: Wed, 11 Nov 2026 15:30:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-209223@kernel.org> (raw)
In-Reply-To: <06579bd381e516e66f97d7b0c00e55d019011a7e.1794399387.git.memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] bpf: broken IRQ state restoration for spinlocks in
bpf_unwind_release_frame()
--
commit bc130ef20556bd747c8015574438bb24ed4f95b8
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Release resources in hidden slots on bpf_throw()
This commit adds runtime support in bpf_throw() to walk discarded BPF
stack frames and release held locks, IRQ flags, sections, and referenced
objects recorded in frame descriptors.
[ ... ]
> diff --git a/kernel/bpf/unwind.c b/kernel/bpf/unwind.c
> new file mode 100644
> index 0000000000000..3b488a4bd7592
> --- /dev/null
> +++ b/kernel/bpf/unwind.c
[ ... ]
> +static void bpf_unwind_release_frame(struct bpf_unwind_ctx *ctx, const struct bpf_prog *prog, u64 bp)
> +{
> + const struct bpf_prog_aux *fn = bpf_prog_frame_aux(prog);
> + const struct bpf_frame_desc_pool *pool = fn->frame_desc_pool;
> + int passes = ctx->phase == BPF_UNWIND_PHASE_LOCKS ? 2 : 1, pass, s;
> + const struct bpf_frame_desc *d;
> + bool late;
> + u64 fp;
> + u32 i;
> +
> + if (!fn->frame_desc)
> + return;
> + d = pool->desc[fn->frame_desc - 1];
> + fp = bpf_unwind_fp(fn, bp);
> + for (pass = 0; pass < passes; pass++) {
> + for (i = 0; i < d->nent; i++) {
> + const struct bpf_frame_desc_entry *ent = &d->ent[i];
> + const struct bpf_resource *res = &pool->resources[ent->res];
> + u64 *slot = (u64 *)(long)(fp + ent->off);
> + void *handle = (void *)(long)*slot;
> +
> + if (ent->flags & BPF_FRAME_ENT_COUNTER) {
> + if (ctx->phase != BPF_UNWIND_PHASE_LOCKS || pass)
> + continue;
> + s = section_index(res->kind);
> + ctx->section[s] = res;
> + ctx->nr_sections[s] += (s64)*slot;
> + continue;
> + }
> + if (!handle || release_phase(res) != ctx->phase)
> + continue;
> + late = res->kind == BPF_RESOURCE_IRQ_FLAG &&
> + !arch_irqs_disabled_flags(*(unsigned long *)handle);
> + if (passes == 2 && late != (pass == 1))
> + continue;
> + bpf_unwind_release(res, handle);
> + }
> + }
> +}
[Severity: High]
Does releasing BPF_RESOURCE_SPIN_LOCK in pass 0 corrupt the CPU interrupt
state when a frame holds both a bpf_spin_lock and a nested
bpf_res_spin_lock_irqsave()?
bpf_spin_lock() saves interrupt flags in per-CPU irqsave_flags and
disables local interrupts, and bpf_spin_unlock() restores irqsave_flags:
kernel/bpf/helpers.c:__bpf_spin_unlock_irqrestore() {
unsigned long flags;
flags = __this_cpu_read(irqsave_flags);
__bpf_spin_unlock(lock);
local_irq_restore(flags);
}
bpf_res_spin_lock() and bpf_res_spin_lock_irqsave() are marked
KF_SPINLOCK_SAFE and can be acquired while a bpf_spin_lock is held. When
a frame acquires bpf_spin_lock() with interrupts enabled and then calls
bpf_res_spin_lock_irqsave(), irqsave_flags holds the enabled state while
the stack slot for BPF_RESOURCE_IRQ_FLAG records interrupts as disabled.
Because only BPF_RESOURCE_IRQ_FLAG is checked for late, pass 0 runs
bpf_spin_unlock() first, re-enabling interrupts while the resilient
spinlock is still held, and then runs bpf_local_irq_restore() on the
BPF_RESOURCE_IRQ_FLAG slot, leaving local interrupts permanently disabled
through sleeping destructors in BPF_UNWIND_PHASE_OBJS and after the BPF
program returns. In addition, releasing BPF_RESOURCE_RES_LOCK in pass 0
calls preempt_enable() in bpf_res_spin_unlock() before pass 1 restores
the interrupt state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794399387.git.memxor@gmail.com?part=12
next prev parent reply other threads:[~2026-11-11 15:30 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:56 [PATCH bpf-next v1 00/29] Exceptions - Resource Cleanup - Redux Kumar Kartikeya Dwivedi
2026-11-11 12:56 ` [PATCH bpf-next v1 01/29] bpf: Record where JITs save callee-saved registers Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 02/29] bpf: Add bpf_throw_unwind() and an arch entry hook Kumar Kartikeya Dwivedi
2026-11-11 14:45 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 03/29] bpf, x86: Capture registers in a native bpf_throw() entry Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 04/29] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 05/29] bpf: Restore callee-saved registers from unwound frames Kumar Kartikeya Dwivedi
2026-11-11 14:41 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 06/29] bpf: Keep last insn's aux data in add_hidden_subprog() Kumar Kartikeya Dwivedi
2026-11-11 14:38 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 07/29] bpf: Add one allocator for hidden stack slots Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 15:15 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 08/29] bpf: Add flags and release kfuncs to the dtor registry Kumar Kartikeya Dwivedi
2026-11-11 13:33 ` bot+bpf-ci
2026-11-11 15:36 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 09/29] bpf: Register cleanup destructors for more types Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 15:00 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 10/29] bpf: Record where JITed frames keep the BPF stack Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 11/29] bpf: Give every reference an owner frame Kumar Kartikeya Dwivedi
2026-11-11 13:33 ` bot+bpf-ci
2026-11-11 12:57 ` [PATCH bpf-next v1 12/29] bpf: Release resources in hidden slots on bpf_throw() Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 15:30 ` sashiko-bot [this message]
2026-11-11 12:57 ` [PATCH bpf-next v1 13/29] bpf: Track held resources in hidden stack slots Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 16:12 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 14/29] bpf: Describe held resources at throw sites Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 12:57 ` [PATCH bpf-next v1 15/29] bpf: Describe handles in registers " Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 16:11 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 16/29] bpf: Describe locks " Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 16:04 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 17/29] bpf: Apply hidden slot limits only when a slot is needed Kumar Kartikeya Dwivedi
2026-11-11 16:31 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 18/29] bpf: Allow a callee to leave resources with its caller Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 16:41 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 19/29] bpf: Allow a callee to release its caller's resources Kumar Kartikeya Dwivedi
2026-11-11 17:02 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 20/29] bpf: Transfer a reference to the callee that releases it Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 16:57 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 21/29] bpf: Support callx when a callee releases resources Kumar Kartikeya Dwivedi
2026-11-11 14:04 ` bot+bpf-ci
2026-11-11 17:13 ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 22/29] selftests/bpf: Test rejected throws that hold resources Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 23/29] selftests/bpf: Test resource cleanup on bpf_throw() Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 24/29] selftests/bpf: Test cleanup of handles on the stack Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 25/29] selftests/bpf: Test cleanup of handles in registers Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 26/29] selftests/bpf: Test callees releasing caller resources Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 27/29] selftests/bpf: Test resources a callee leaves with its caller Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 28/29] selftests/bpf: Test cleanup of locks described at sites Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 29/29] selftests/bpf: Test callee releases through callx Kumar Kartikeya Dwivedi
2026-11-11 20:33 ` [PATCH bpf-next v1 00/29] Exceptions - Resource Cleanup - Redux 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-209223@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 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.