BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	alexei.starovoitov@gmail.com, 	andrii@kernel.org,
	daniel@iogearbox.net, memxor@gmail.com, martin.lau@kernel.org,
		mykyta.yatsenko5@gmail.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v4 07/12] bpf: Unify referenced object tracking in verifier
Date: Tue, 12 May 2026 14:28:50 -0700	[thread overview]
Message-ID: <073fd24d1220adccec5248b094f4f80fd5e66f93.camel@gmail.com> (raw)
In-Reply-To: <CAMB2axOsnVj=PBuMU8utqKsSj7DsVhWNi9Vddytx6BKfFGs0JQ@mail.gmail.com>

On Tue, 2026-05-12 at 23:27 +0200, Amery Hung wrote:
> On Tue, May 12, 2026 at 2:09 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > 
> > On Tue, 2026-05-12 at 22:37 +0200, Amery Hung wrote:
> > > On Tue, May 12, 2026 at 12:04 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > > > 
> > > > On Wed, 2026-05-06 at 07:27 -0700, Amery Hung wrote:
> > > > 
> > > > LGTM, a nit below.
> > > > 
> > > > [...]
> > > > 
> > > > > @@ -8028,14 +8024,13 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,
> > > > >       }
> > > > > 
> > > > >       if (reg->ref_obj_id && base_type(arg_type) != ARG_KPTR_XCHG_DEST) {
> > > > > -             if (meta->ref_obj_id) {
> > > > > -                     verbose(env, "more than one arg with ref_obj_id R%d %u %u",
> > > > > -                             regno, reg->ref_obj_id,
> > > > > -                             meta->ref_obj_id);
> > > > > +             if (meta->release_regno && meta->ref_obj.cnt) {
> > > > > +                     verbose(env, "more than one arg with ref_obj_id %s %u %u",
> > > > > +                             reg_arg_name(env, argno), reg->ref_obj_id,
> > > > > +                             meta->ref_obj.ref_obj_id);
> > > > 
> > > > I think this should be reported from update_ref_obj() itself,
> > > > it is more consistent logically and also avoids reporting code
> > > > duplication in check_kfunc_args() and check_kfunc_call().
> > > > Also, technically the reg_arg_name() is an independent fix.
> > > 
> > > We have kfuncs that have more than one ref_obj. This is not a problem
> > > unless ref_obj is referenced in the verification and is ambiguous
> > > (e.g., used it to tie the lifetime of the allocated memory with
> > > ref_obj). Therefore, it is kept at the location of use instead of
> > > update_ref_obj() to prevent breaking existing kfuncs.
> > 
> > Ack, thank you for explaining.
> > 
> > > > 
> > > > > Drop the selftest introduced in 7ec899ac90a2 (“selftests/bpf: Negative
> > > > > test case for ref_obj_id in args”) since the verifier no longer
> > > > > complains about ambiguous ref_obj if it is not used.
> > > > 
> > > > On the other hand, if you think that this property is worth having,
> > > > then maybe wrap the check with in some utility function?
> > > 
> > > A utility function like below makes sense if we fold ref_obj_id into
> > > id. It would be too cumbersome for v3 as we may need two of this for
> > > ref_obj->ref_obj_id and ref_obj->id.
> > > 
> > > static int get_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;
> > >         }
> > >         return ref_obj->id;
> > > }
> > 
> > Maybe just like this:
> > 
> >   static void validate_ref_obj(struct ref_obj_desc *d) { ... }
> > 
> 
> Do you mean:
> static int validate_ref_obj(struct ref_obj_desc *d) { ... }
> 
> Then to use it:
> err = validate_ref_obj(meta.ref_obj);
> if (err)
>         return err;
> 
> regs[BPF_REG_0].ref_obj_id = meta.ref_obj.ref_obj_id;
> 
> > ?

Yes, like that, sorry.

  reply	other threads:[~2026-05-12 21:29 UTC|newest]

Thread overview: 40+ 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-12 20:13     ` Amery Hung
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-12 18:32   ` Eduard Zingerman
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-12 19:03   ` Eduard Zingerman
2026-05-12 20:37     ` Amery Hung
2026-05-12 21:09       ` Eduard Zingerman
2026-05-12 21:27         ` Amery Hung
2026-05-12 21:28           ` Eduard Zingerman [this message]
2026-05-12 21:31             ` 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-12 20:19   ` Eduard Zingerman
2026-05-12 21:22     ` Amery Hung
2026-05-12 21:25       ` Eduard Zingerman
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=073fd24d1220adccec5248b094f4f80fd5e66f93.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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