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.6.y v2 2/3] bpf: Propagate referenced dynptr release errors
Date: Sat, 29 Aug 2026 10:42:14 +0000	[thread overview]
Message-ID: <20260829104214.9F4B01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260829102618.105116-3-xyx2021@mail.ustc.edu.cn>

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

Pre-existing issues:
- [High] The commit fixes a kernel panic where a callback releasing a caller-acquired dynptr reference triggers a WARN_ON_ONCE, but leaves the identical vulnerability unfixed for BPF iterators in unmark_stack_slots_iter().
- [High] A kernel panic can be triggered via WARN_ON_ONCE(release_reference_state(...)) in mark_ptr_or_null_regs() when performing a NULL check on a caller's spilled PTR_OR_NULL register inside a callback.
--

commit 0666efa4fca54b7a83f6a6c69d44d1c775940a2e
Author: Amery Hung <ameryhung@gmail.com>
Subject: bpf: Propagate referenced dynptr release errors

This patch fixes a panic caused by a WARN_ON_ONCE in the verifier when a BPF
callback incorrectly attempts to release a referenced dynptr acquired by its
caller. It does this by correctly propagating the error returned from
release_reference() in unmark_stack_slots_dynptr().

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 ad679bc42427c..c9e3856bb59fd 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -1013,8 +1017,16 @@ static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_re
>  	 * 2) Any slices derived from this dynptr.
>  	 */
>  
> -	/* Invalidate any slices associated with this dynptr */
> -	WARN_ON_ONCE(release_reference(env, ref_obj_id));
> +	/* Invalidate any slices associated with this dynptr.
> +	 * release_reference() only walks registers that carry ref_obj_id;
> +	 * slices are PTR_TO_MEM with dynptr_id set and ref_obj_id left 0.
> +	 * Mirror destroy_if_dynptr_stack_slot(), which already invalidates
> +	 * slices by dynptr_id.
> +	 */
> +	err = release_reference(env, ref_obj_id);
> +	if (err)
> +		return err;

[Severity: High]
This isn't a bug introduced by this patch, but does the same vulnerability
still exist for BPF iterators in unmark_stack_slots_iter()?

If a caller allocates an iterator on its stack, passes a pointer to this stack
slot into a callback via bpf_loop(), and the callback invokes a destroy kfunc
(like bpf_iter_num_destroy()), the verifier will call:

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

Because the reference belongs to the caller frame, release_reference() returns
-EINVAL, which triggers the WARN_ON_ONCE and panics the kernel if
panic_on_warn=1.

[Severity: High]
This is a pre-existing issue, but could a similar panic occur when performing
a NULL check on a caller's spilled PTR_OR_NULL register inside a callback?

If a caller acquires a reference-tracked pointer that could be NULL, spills it
to the stack, and passes a pointer to that stack slot to a callback, the
restored register preserves the caller's id and ref_obj_id.

When the callback performs a NULL check on this restored pointer:

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));
    ...
}

Because the reference belongs to the caller frame, release_reference_state()
returns -EINVAL, triggering the warning.

> +	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++) {

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

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

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  3:27 [PATCH 6.6.y 0/2] bpf: fix dynptr lifetime invalidation on release Xu Yunxiang
2026-08-29  3:36 ` [PATCH 6.6.y 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.6.y 2/2] bpf: Invalidate dynptr clones in every call frame " Xu Yunxiang
2026-08-29  4:07   ` sashiko-bot
2026-09-09  4:28     ` [PATCH bpf 0/2] bpf: Preserve escaped dynptr slice ancestry Xu Yunxiang
2026-09-09  4:28       ` [PATCH bpf 1/2] bpf: Preserve escaped dynptr slice ancestry on subprog return Xu Yunxiang
2026-09-09  5:18         ` bot+bpf-ci
2026-09-09  4:28       ` [PATCH bpf 2/2] selftests/bpf: Test slices escaping a clone call frame Xu Yunxiang
2026-09-09  4:34         ` sashiko-bot
2026-09-09  5:18         ` bot+bpf-ci
2026-08-29 10:26 ` [PATCH 6.6.y v2 0/3] bpf: fix dynptr release handling Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.6.y v2 1/3] bpf: Invalidate dynptr slices by dynptr_id on release Xu Yunxiang
2026-08-29 10:26   ` [PATCH 6.6.y v2 2/3] bpf: Propagate referenced dynptr release errors Xu Yunxiang
2026-08-29 10:42     ` sashiko-bot [this message]
2026-08-29 10:26   ` [PATCH 6.6.y v2 3/3] bpf: Invalidate dynptr clones in every call frame on release Xu Yunxiang
2026-08-30  2:56   ` [PATCH 6.6.y v2 0/3] bpf: fix dynptr release handling Sasha Levin

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=20260829104214.9F4B01F000E9@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.