All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] bpf: Invalidate dynptr clones in every call frame on release
       [not found] <apD0GtLd8lXgXD2e@1wt.eu>
@ 2026-08-28  4:46 ` Xu Yunxiang
  2026-08-28  5:24   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Xu Yunxiang @ 2026-08-28  4:46 UTC (permalink / raw)
  To: Willy Tarreau
  Cc: Alexei Starovoitov, Daniel Borkmann, security, andrii, memxor,
	eddyz87, Amery Hung, Greg Kroah-Hartman, stable

unmark_stack_slots_dynptr() walks clones only in the submitting
pointer's frame. A program that clones a ringbuf dynptr in a subprog,
submits the clone, then submits the original in the caller is therefore
accepted: the caller's STACK_DYNPTR slot is never cleared. The second
bpf_ringbuf_commit() flips BUSY on an already-committed header and a
userspace consumer stalls.

Walk every frame and invalidate matching STACK_DYNPTR slots, the same
per-slot work destroy_if_dynptr_stack_slot() already does in one frame.
Leave the existing WARN_ON_ONCE(release_reference()) as a swallow: a
hard -EINVAL would reject legitimate programs that release once in a
different frame than they acquired (6.6/6.12/6.13), and on 6.14+ the
second lookup fails because the ref was already deleted.

Depends on "bpf: Invalidate dynptr slices by dynptr_id on release" only
for the slice helper call inside the new loop; the frame walk is
independent.

This is the minimal stable equivalent of the cross-frame half of
308c7a0ae8859. That refactor is not a viable cherry-pick for stable.

Cc: stable@vger.kernel.org # 6.6.y 6.12.y 6.18.y

Signed-off-by: Xu Yunxiang <xyx2021@mail.ustc.edu.cn>
---
 kernel/bpf/verifier.c | 43 +++++++++++++++++++++
 1 file changed

--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -811,7 +811,7 @@
 static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_state *reg)
 {
 	struct bpf_func_state *state = func(env, reg);
-	int spi, ref_obj_id, i;
+	int spi, ref_obj_id, i, frm;
 
 	spi = dynptr_get_spi(env, reg);
 	if (spi < 0)
@@ -843,22 +843,33 @@
 	WARN_ON_ONCE(release_reference(env, ref_obj_id));
 	invalidate_slices_of_dynptr(env, state->stack[spi].spilled_ptr.id);
 
-	/* Invalidate any dynptr clones */
-	for (i = 1; i < state->allocated_stack / BPF_REG_SIZE; i++) {
-		if (state->stack[i].spilled_ptr.ref_obj_id != ref_obj_id)
-			continue;
+	/* Invalidate any dynptr clones, including those in other frames.
+	 * acquired_refs is per-frame on 6.6/6.12/6.13; a clone submitted in a
+	 * callee must still clear the caller's STACK_DYNPTR slot. Do not turn
+	 * a failing release_reference() into -EINVAL: that rejects legitimate
+	 * cross-frame single releases on those trees.
+	 */
+	for (frm = 0; frm <= env->cur_state->curframe; frm++) {
+		struct bpf_func_state *f = env->cur_state->frame[frm];
 
-		/* it should always be the case that if the ref obj id
-		 * matches then the stack slot also belongs to a
-		 * dynptr
-		 */
-		if (state->stack[i].slot_type[0] != STACK_DYNPTR) {
-			verbose(env, "verifier internal error: misconfigured ref_obj_id\n");
-			return -EFAULT;
-		}
-		if (state->stack[i].spilled_ptr.dynptr.first_slot) {
-			invalidate_slices_of_dynptr(env, state->stack[i].spilled_ptr.id);
-			invalidate_dynptr(env, state, i);
+		if (!f)
+			continue;
+		for (i = 1; i < f->allocated_stack / BPF_REG_SIZE; i++) {
+			if (f->stack[i].spilled_ptr.ref_obj_id != ref_obj_id)
+				continue;
+
+			/* it should always be the case that if the ref obj id
+			 * matches then the stack slot also belongs to a
+			 * dynptr
+			 */
+			if (f->stack[i].slot_type[0] != STACK_DYNPTR) {
+				verbose(env, "verifier internal error: misconfigured ref_obj_id\n");
+				return -EFAULT;
+			}
+			if (f->stack[i].spilled_ptr.dynptr.first_slot) {
+				invalidate_slices_of_dynptr(env, f->stack[i].spilled_ptr.id);
+				invalidate_dynptr(env, f, i);
+			}
 		}
 	}
 
-- 
BPF-SemSan disclosure follow-up


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] bpf: Invalidate dynptr clones in every call frame on release
  2026-08-28  4:46 ` [PATCH 2/2] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang
@ 2026-08-28  5:24   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2026-08-28  5:24 UTC (permalink / raw)
  To: Xu Yunxiang
  Cc: Willy Tarreau, Alexei Starovoitov, Daniel Borkmann, security,
	andrii, memxor, eddyz87, Amery Hung, stable

On Fri, Aug 28, 2026 at 12:46:49PM +0800, Xu Yunxiang wrote:
> unmark_stack_slots_dynptr() walks clones only in the submitting
> pointer's frame. A program that clones a ringbuf dynptr in a subprog,
> submits the clone, then submits the original in the caller is therefore
> accepted: the caller's STACK_DYNPTR slot is never cleared. The second
> bpf_ringbuf_commit() flips BUSY on an already-committed header and a
> userspace consumer stalls.
> 
> Walk every frame and invalidate matching STACK_DYNPTR slots, the same
> per-slot work destroy_if_dynptr_stack_slot() already does in one frame.
> Leave the existing WARN_ON_ONCE(release_reference()) as a swallow: a
> hard -EINVAL would reject legitimate programs that release once in a
> different frame than they acquired (6.6/6.12/6.13), and on 6.14+ the
> second lookup fails because the ref was already deleted.
> 
> Depends on "bpf: Invalidate dynptr slices by dynptr_id on release" only
> for the slice helper call inside the new loop; the frame walk is
> independent.
> 
> This is the minimal stable equivalent of the cross-frame half of
> 308c7a0ae8859. That refactor is not a viable cherry-pick for stable.
> 
> Cc: stable@vger.kernel.org # 6.6.y 6.12.y 6.18.y
> 
> Signed-off-by: Xu Yunxiang <xyx2021@mail.ustc.edu.cn>
> ---
>  kernel/bpf/verifier.c | 43 +++++++++++++++++++++
>  1 file changed

Same here, you lost the authorship and signed-off-by of the original.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-28  5:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <apD0GtLd8lXgXD2e@1wt.eu>
2026-08-28  4:46 ` [PATCH 2/2] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang
2026-08-28  5:24   ` Greg Kroah-Hartman

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.