BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amery Hung" <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 05/12] bpf: Refactor object relationship tracking and fix dynptr UAF bug
Date: Wed, 06 May 2026 21:54:37 +0000	[thread overview]
Message-ID: <20260506215438.45B98C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260506142709.2298255-6-ameryhung@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Dynptrs constructed from referenced objects are assigned a `parent_id` of 0, breaking cascading invalidation and leading to Use-After-Free.
--

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

bpf: Refactor object relationship tracking and fix dynptr UAF bug

This commit refactors verifier object relationship tracking by replacing
the PTR_TO_MEM-specific dynptr_id with a general parent_id in bpf_reg_state.
It updates release_reference() to use a DFS approach for cascading
invalidation when parent objects are freed.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -11804,15 +11810,10 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_
>  				}
>  
>  				dynptr_arg_type |= (unsigned int)get_dynptr_type_flag(parent_type);
>  			}
>  
>  			ret = process_dynptr_func(env, reg, argno, insn_idx, dynptr_arg_type,
> -						  clone_ref_obj_id, &meta->dynptr);
> +						  meta->ref_obj_id ? meta->id : 0, &meta->dynptr);

Does this code assign 0 to the dynptr's parent_id instead of the actual
parent's ID?

For referenced objects acquired with PTR_MAYBE_NULL, the BPF program must
perform a NULL check before passing the pointer to the constructor. Upon a
successful NULL check, the verifier clears reg->id to 0 while preserving
reg->ref_obj_id.

Consequently, meta->id appears to be unconditionally 0 when the dynptr is
constructed here.

When the parent object is subsequently released, the DFS traversal in
release_reference() searches for descendants matching reg->parent_id == id.
Because the dynptr's parent_id was initialized to 0, does this cause the
dynptr to evade invalidation and remain fully active, leading to a
use-after-free regression?

Should this pass meta->ref_obj_id instead of meta->id?

>  			if (ret < 0)
>  				return ret;
>  			break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260506142709.2298255-1-ameryhung@gmail.com?part=5

  parent reply	other threads:[~2026-05-06 21:54 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06 14:26 [PATCH bpf-next v4 00/12] Refactor verifier object relationship tracking Amery Hung
2026-05-06 14:26 ` [PATCH bpf-next v4 01/12] bpf: Simplify mark_stack_slot_obj_read() and callers Amery Hung
2026-05-11 17:17   ` Eduard Zingerman
2026-05-06 14:26 ` [PATCH bpf-next v4 02/12] bpf: Unify dynptr handling in the verifier Amery Hung
2026-05-06 15:27   ` bot+bpf-ci
2026-05-07 12:22     ` Amery Hung
2026-05-06 14:26 ` [PATCH bpf-next v4 03/12] bpf: Assign reg->id when getting referenced kptr from ctx Amery Hung
2026-05-06 15:27   ` bot+bpf-ci
2026-05-07 12:38     ` Amery Hung
2026-05-11 21:31   ` Eduard Zingerman
2026-05-06 14:27 ` [PATCH bpf-next v4 04/12] bpf: Preserve reg->id of pointer objects after null-check Amery Hung
2026-05-11 21:48   ` Eduard Zingerman
2026-05-06 14:27 ` [PATCH bpf-next v4 05/12] bpf: Refactor object relationship tracking and fix dynptr UAF bug Amery Hung
2026-05-06 15:27   ` bot+bpf-ci
2026-05-07 12:20     ` Amery Hung
2026-05-06 21:54   ` sashiko-bot [this message]
2026-05-07 12:52     ` Amery Hung
2026-05-12  2:28   ` Eduard Zingerman
2026-05-06 14:27 ` [PATCH bpf-next v4 06/12] bpf: Remove redundant dynptr arg check for helper Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 07/12] bpf: Unify referenced object tracking in verifier Amery Hung
2026-05-06 22:48   ` sashiko-bot
2026-05-07 12:55     ` Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 08/12] bpf: Unify release handling for helpers and kfuncs Amery Hung
2026-05-06 23:59   ` sashiko-bot
2026-05-07 13:23     ` Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 09/12] selftests/bpf: Test creating dynptr from dynptr data and slice Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 10/12] selftests/bpf: Test using dynptr after freeing the underlying object Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 11/12] selftests/bpf: Test using slice after invalidating dynptr clone Amery Hung
2026-05-06 14:27 ` [PATCH bpf-next v4 12/12] selftests/bpf: Test using file dynptr after the reference on file is dropped Amery Hung

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=20260506215438.45B98C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ameryhung@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox