From: sashiko-bot@kernel.org
To: "Xu Yunxiang" <xyx2021@mail.ustc.edu.cn>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 1/2] bpf: Preserve escaped dynptr slice ancestry on subprog return
Date: Thu, 10 Sep 2026 05:01:26 +0000 [thread overview]
Message-ID: <20260910050127.31A8E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910044006.2279547-2-xyx2021@mail.ustc.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] A subprogram can return or spill a memory slice (PTR_TO_MEM) derived from a local dynptr backed by its own stack frame, leading to a stack Use-After-Free in the caller.
- [Critical] Creating a local dynptr from a referenced dynptr slice via bpf_dynptr_from_mem strips lifetime tracking, allowing use-after-free.
--
commit 670ebab06aaf35b7713f2c4efe3dba56988a2162
Author: Xu Yunxiang <xyx2021@mail.ustc.edu.cn>
bpf: Preserve escaped dynptr slice ancestry on subprog return
Before freeing a callee, reparent surviving PTR_TO_MEM slices of every
dynptr with a parent to that parent. This preserves the lifetime link after
the local dynptr disappears for both reference-owning dynptrs and dynptrs
constructed from referenced objects.
Link: https://lore.kernel.org/r/20260829040712.B1B511F000E9@smtp.kernel.org
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 72a3f5998dd27..ee41b7386f752 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -800,6 +800,39 @@ static int dynptr_ref_cnt(struct bpf_verifier_env *env, int v_parent_id)
> return ref_cnt;
> }
>
> +static void reparent_dynptr_slices_on_func_exit(struct bpf_verifier_env *env,
> + struct bpf_func_state *callee)
> +{
> + struct bpf_verifier_state *vstate = env->cur_state;
> + struct bpf_func_state *state;
> + struct bpf_reg_state *reg;
> + int i;
> +
> + for (i = 0; i < callee->allocated_stack / BPF_REG_SIZE; i++) {
> + struct bpf_stack_state *slot = &callee->stack[i];
> + struct bpf_reg_state *dynptr = &slot->spilled_ptr;
> +
> + if (slot->slot_type[0] != STACK_DYNPTR ||
> + !dynptr->dynptr.first_slot ||
> + !dynptr->parent_id)
> + continue;
[Severity: Critical]
This is a pre-existing issue, but does this logic leave a gap for local
dynptrs backed by a callee's stack frame?
Because local dynptrs have parent_id = 0, they are skipped here. This seems
to allow a subprogram to return or spill a PTR_TO_MEM slice derived from a
local dynptr into the caller's state.
Since prepare_func_exit() only prevents returning PTR_TO_STACK in R0, could a
PTR_TO_MEM alias created via bpf_dynptr_data() escape and allow a stack
use-after-free in the caller?
[ ... ]
[Severity: Critical]
This is also a pre-existing issue, but does bpf_dynptr_from_mem() strip
lifetime tracking when used with referenced dynptr slices?
If a program reserves a ringbuf dynptr, gets a PTR_TO_MEM slice via
bpf_dynptr_data(), and then passes that slice to bpf_dynptr_from_mem():
kernel/bpf/helpers.c:bpf_dynptr_from_mem_proto() {
...
.arg1_type = ARG_PTR_TO_UNINIT_MEM,
...
}
kernel/bpf/verifier.c:mark_stack_slots_dynptr() {
...
parent_id = ref_obj->id;
...
}
The new dynptr's parent_id is incorrectly assigned 0 because the slice's
parent_id is not propagated. Could the resulting local dynptr be accessed
after the original ringbuf reservation is discarded, leading to a
use-after-free of referenced kernel objects?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910044006.2279547-1-xyx2021@mail.ustc.edu.cn?part=1
next prev parent reply other threads:[~2026-09-10 5:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 4:40 [PATCH bpf v2 0/2] bpf: Preserve escaped dynptr slice ancestry Xu Yunxiang
2026-09-10 4:40 ` [PATCH bpf v2 1/2] bpf: Preserve escaped dynptr slice ancestry on subprog return Xu Yunxiang
2026-09-10 5:01 ` sashiko-bot [this message]
2026-09-10 8:07 ` Xu Yunxiang
2026-09-10 17:22 ` Amery Hung
2026-09-10 4:40 ` [PATCH bpf v2 2/2] selftests/bpf: Test dynptr slices escaping a call frame 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=20260910050127.31A8E1F000FF@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.