Re: [PATCH bpf v3 1/4] bpf: Keep refcount_acquire nullable for borrowed RCU kptrs
Amery Hung <[email protected]> Mon, 3 Aug 2026 06:45:59 -0700
| Newsgroups | org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kernel.vger.stable |
|---|---|
| Message-ID | <CAMB2axObnCmR91CTZjf8egdskM-DGVqaArK5n+YYmACUfSOOAA@mail.gmail.com> |
On Mon, Aug 3, 2026 at 6:14=E2=80=AFAM <[email protected]> wrote: > > > bpf: Keep refcount_acquire nullable for borrowed RCU kptrs > > > > The verifier can mistake an RCU-loaded map kptr for an owned reference = and > > assume bpf_refcount_acquire() cannot return NULL. The kfunc uses > > refcount_inc_not_zero(), so it can return NULL after the last reference= is > > dropped. Passing that unchecked result to bpf_obj_drop() can crash the > > kernel. > > > > Only treat the argument as owned when the verifier tracks an acquired > > reference for it. Borrowed pointers remain nullable, while owned pointe= rs > > keep the existing behavior. > > > > Fixes: 1b12171533a9 ("bpf: Mark direct ld of stashed bpf_{rb,list}_node= as non-owning ref") ^^^ The fix tag is correct. Reviewed-by: Amery Hung <[email protected]> > > Does this Fixes tag point to the right commit? > > Looking at the code change, the fix adds && reg_is_referenced(env, reg) > to an existing condition that checks !type_is_non_owning_ref(reg->type). > The problem being fixed is that the verifier incorrectly assumes pointers > that are not non-owning refs must be owning refs, which fails to account > for borrowed RCU pointers. > > The commit 1b12171533a9 added logic to mark certain pointers as > non-owning refs, but the bug appears to originate from commit > 7793fc3babe9 ("bpf: Make bpf_refcount_acquire fallible for non-owning > refs"), which introduced the logic: > > if (!type_is_non_owning_ref(reg->type)) > meta->arg_owning_ref =3D true; > > That commit incorrectly assumed pointers that are not non-owning refs > must be owning refs, missing the case of borrowed RCU pointers which are > neither. The current fix addresses this by verifying the verifier tracks > an acquired reference before treating the pointer as owned. > > Should the Fixes tag be: > > Fixes: 7793fc3babe9 ("bpf: Make bpf_refcount_acquire fallible for non-o= wning refs") > > > --- > AI reviewed your patch. Please fix the bug or email reply why it's not a = bug. > See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/READM= E.md > > CI run summary: https://github.com/kernel-patches/bpf/actions/runs/308109= 49269