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 08/12] bpf: Unify release handling for helpers and kfuncs
Date: Tue, 12 May 2026 14:25:41 -0700 [thread overview]
Message-ID: <9f6923ed86fcaf228000f7a83ace638ae523161e.camel@gmail.com> (raw)
In-Reply-To: <CAMB2axO3pL5uCLL-=Ov7Nnyf7_=8tL+j0vUNHRV=Z8EFg66hyQ@mail.gmail.com>
On Tue, 2026-05-12 at 23:22 +0200, Amery Hung wrote:
[...]
> > > @@ -9870,37 +9928,11 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
> > > }
> > >
> > > if (meta.release_regno) {
> > > - err = -EINVAL;
> > > - if (arg_type_is_dynptr(fn->arg_type[meta.release_regno - BPF_REG_1])) {
> > > - err = unmark_stack_slots_dynptr(env, ®s[meta.release_regno]);
> > > - } else if (func_id == BPF_FUNC_kptr_xchg && meta.ref_obj.ref_obj_id) {
> > > - u32 ref_obj_id = meta.ref_obj.ref_obj_id;
> > > - bool in_rcu = in_rcu_cs(env);
> > > - struct bpf_func_state *state;
> > > - struct bpf_reg_state *reg;
> > > -
> > > - err = release_reference_nomark(env->cur_state, ref_obj_id);
> > > - if (!err) {
> > > - bpf_for_each_reg_in_vstate(env->cur_state, state, reg, ({
> > > - if (reg->ref_obj_id == ref_obj_id) {
> > > - if (in_rcu && (reg->type & MEM_ALLOC) && (reg->type & MEM_PERCPU)) {
> > > - reg->ref_obj_id = 0;
> > > - reg->type &= ~MEM_ALLOC;
> > > - reg->type |= MEM_RCU;
> > > - } else {
> > > - mark_reg_invalid(env, reg);
> >
> > Note: release_reg() does not have this 'else' path, but it seem to be not a problem,
> > assuming that MEM_ALLOC | MEM_PERCPU registers are generated only from some
> > other cmp_xchg call. Is that the case?
>
> AFAIK, percpu allocated objects (i.e., MEM_ALLOC | MEM_PERCPU
> registers) only come from bpf_kptr_xchg() and bpf_percpu_obj_new(). We
> don't have a mechanism to derive registers from percpu allocated
> objects such that we need to mark_reg_invalid when calling
> bpf_kptr_xchg().
>
> If there is such case in the future, maybe we can do the following in
> release_reg() then
>
> if (convert_rcu)
> err = ref_convert_alloc_rcu_protected(env, reg->ref_obj_id);
>
> if (release_dynptr)
> err = unmark_stack_slots_dynptr(env, reg);
> else if (reg->ref_obj_id)
> err = release_reference(env, reg->ref_obj_id);
> else if (bpf_register_is_null(reg))
> err = 0;
Thank you for explaining, in such case I think the code is good as it is.
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
next prev parent reply other threads:[~2026-05-12 21:26 UTC|newest]
Thread overview: 34+ 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-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-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
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-12 20:19 ` Eduard Zingerman
2026-05-12 21:22 ` Amery Hung
2026-05-12 21:25 ` Eduard Zingerman [this message]
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=9f6923ed86fcaf228000f7a83ace638ae523161e.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