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 07/12] bpf: Unify referenced object tracking in verifier
Date: Wed, 06 May 2026 22:48:32 +0000	[thread overview]
Message-ID: <20260506224833.71FC4C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260506142709.2298255-8-ameryhung@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The verifier uses `verifier_bug()` to handle ambiguous referenced object arguments, allowing user input to potentially trigger kernel warnings.
--

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

    bpf: Unify referenced object tracking in verifier

This commit unifies the reference tracking logic used by helpers and kfuncs
into a common ref_obj_desc structure. It updates tracking mechanisms and 
pushes validation of ambiguous referenced objects out to their use locations.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 792e61e07b065..542912c7983f7 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -713,6 +700,13 @@ static int mark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_
>  				return ref_obj_id;
>  		}
>  		/* Track parent's id if the parent is a referenced object */
> +		if (ref_obj && ref_obj->ref_obj_id) {
> +			if (ref_obj->cnt > 1) {
> +				verifier_bug(env, "function expects only one referenced object but got %d\n", ref_obj->cnt);
> +				return -EFAULT;
> +			}
> +			parent_id = ref_obj->id;
> +		}

Since ref_obj->cnt is determined by the number of referenced arguments
provided by the BPF program, is it possible for a user to intentionally
trigger this verifier_bug() by passing multiple referenced objects?

Since verifier_bug() expands to BPF_WARN_ONCE(), triggering a warning
via unprivileged or user-controlled input could be problematic if
panic_on_warn is enabled.

Would it be safer to gracefully reject the program using verbose() and
returning -EINVAL, similar to how it is handled for release kfuncs earlier
in this patch?

This same pattern appears in a few other places introduced by this patch:

[ ... ]
> @@ -10165,15 +10160,14 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
>  	if (type_may_be_null(regs[BPF_REG_0].type))
>  		regs[BPF_REG_0].id = ++env->id_gen;
>  
> -	if (helper_multiple_ref_obj_use(func_id, meta.map.ptr)) {
> -		verifier_bug(env, "func %s#%d sets ref_obj_id more than once",
> -			     func_id_name(func_id), func_id);
> -		return -EFAULT;
> -	}
> -
>  	if (is_ptr_cast_function(func_id)) {
>  		/* For release_reference() */
> -		regs[BPF_REG_0].ref_obj_id = meta.ref_obj_id;
> +		if (meta.ref_obj.cnt > 1) {
> +			verifier_bug(env, "function expects only one referenced object but got %d\n",
> +				     meta.ref_obj.cnt);
> +			return -EFAULT;
> +		}
> +		regs[BPF_REG_0].ref_obj_id = meta.ref_obj.ref_obj_id;

[ ... ]
> @@ -12740,8 +12733,14 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>  				regs[BPF_REG_0].type |= MEM_RDONLY;
>  
>  			/* Ensures we don't access the memory after a release_reference() */
> -			if (meta.ref_obj_id)
> -				regs[BPF_REG_0].parent_id = meta.ref_obj_id;
> +			if (meta.ref_obj.ref_obj_id) {
> +				if (meta.ref_obj.cnt > 1) {
> +					verifier_bug(env, "function expects only one referenced object but got %d\n",
> +						     meta.ref_obj.cnt);
> +					return -EFAULT;
> +				}
> +				regs[BPF_REG_0].parent_id = meta.ref_obj.ref_obj_id;
> +			}

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

  reply	other threads:[~2026-05-06 22:48 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
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 [this message]
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=20260506224833.71FC4C2BCB0@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