All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Yunxiang" <xyx2021@mail.ustc.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.12.y v3 2/3] bpf: Propagate referenced dynptr release errors
Date: Sat, 29 Aug 2026 10:48:46 +0000	[thread overview]
Message-ID: <20260829104846.F263B1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260829102638.105170-3-xyx2021@mail.ustc.edu.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch successfully fixes a kernel panic by propagating the error from `release_reference()` for dynptrs, but leaves identical vulnerabilities in `unmark_stack_slots_iter()` and `mark_ptr_or_null_regs()`, where `WARN_ON_ONCE` is still used and will trigger panics when callbacks interact with caller references.
--

commit aa0864ea661b640ba7fd188bf0b1fcebb309d1b3
Author: Amery Hung <ameryhung@gmail.com>

bpf: Propagate referenced dynptr release errors

This commit propagates the error from release_reference() for dynptrs to
avoid a kernel panic when a BPF callback attempts to release a caller's
reference. It extracts the upstream behavior for the old stable verifier.

Link: https://lore.kernel.org/r/20260529014936.2811085-6-ameryhung@gmail.com

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index dbc9cfcffcd60..65ee9afaa5ff0 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -838,7 +838,9 @@ static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_re
>  	 * Mirror destroy_if_dynptr_stack_slot(), which already invalidates
>  	 * slices by dynptr_id.
>  	 */
> -	WARN_ON_ONCE(release_reference(env, ref_obj_id));
> +	err = release_reference(env, ref_obj_id);
> +	if (err)
> +		return err;

[Severity: High]
This is a pre-existing issue, but while this successfully fixes the
kernel panic for dynptrs, does it leave identical issues in
unmark_stack_slots_iter() and mark_ptr_or_null_regs()?

For iterators, if a BPF program acquires an iterator (e.g., bpf_iter_num_new) on
the caller's stack, passes it as the ctx argument to bpf_loop(), and calls
bpf_iter_num_destroy() on it from within the callback, unmark_stack_slots_iter()
will still trigger a panic because of WARN_ON_ONCE:

kernel/bpf/verifier.c:unmark_stack_slots_iter() {
	...
	for (i = 0; i < nr_slots; i++) {
		...
		if (i == 0)
			WARN_ON_ONCE(release_reference(env, st->ref_obj_id));
	...
}

Similarly, if a BPF program acquires a reference that can be NULL (e.g.,
bpf_sk_lookup_tcp()), spills it to the caller's stack, passes it as the ctx
argument to bpf_loop(), and performs a NULL check on it inside the callback,
mark_ptr_or_null_regs() also triggers a panic:

kernel/bpf/verifier.c:mark_ptr_or_null_regs() {
	...
	if (ref_obj_id && ref_obj_id == id && is_null)
		/* regs[regno] is in the " == NULL" branch.
		 * No one could have freed the reference state before
		 * doing the NULL check.
		 */
		WARN_ON_ONCE(release_reference_state(state, id));
	...
}

Should these two locations also have their errors correctly propagated instead
of triggering a warning?

>  	invalidate_slices_of_dynptr(env, state->stack[spi].spilled_ptr.id);
>  
>  	/* Invalidate any dynptr clones */

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829102638.105170-1-xyx2021@mail.ustc.edu.cn?part=2

  reply	other threads:[~2026-08-29 10:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  3:37 [PATCH 6.12.y v2 0/2] bpf: fix dynptr lifetime invalidation on release Xu Yunxiang
2026-08-29  3:37 ` [PATCH 6.12.y v2 1/2] bpf: Invalidate dynptr slices by dynptr_id " Xu Yunxiang
2026-08-29  3:56   ` sashiko-bot
2026-08-29  3:37 ` [PATCH 6.12.y v2 2/2] bpf: Invalidate dynptr clones in every call frame " Xu Yunxiang
2026-08-29  4:01   ` sashiko-bot
2026-08-29 10:26 ` [PATCH 6.12.y v3 0/3] bpf: fix dynptr release handling Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.12.y v3 1/3] bpf: Invalidate dynptr slices by dynptr_id on release Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.12.y v3 2/3] bpf: Propagate referenced dynptr release errors Xu Yunxiang
2026-08-29 10:48     ` sashiko-bot [this message]
2026-08-29 10:26   ` [PATCH 6.12.y v3 3/3] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang

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=20260829104846.F263B1F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xyx2021@mail.ustc.edu.cn \
    /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.