]> git.hungrycats.org Git - linux/commit
selftests/bpf: Test borrowed refcount acquisition nullability
authorNing Ding <dingning04@gmail.com>
Fri, 4 Sep 2026 08:43:17 +0000 (10:43 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Sep 2026 14:58:36 +0000 (07:58 -0700)
commit2edd8339468e4bf0feecb3398aaad25fd7b84286
treee5c6fa56a5dcdcfea21adfffa038311f0639fe1f
parentdc36739e5cc9f60485418a910b42bc95339218d2
selftests/bpf: Test borrowed refcount acquisition nullability

Add verifier coverage for the distinction between owning and borrowed
arguments to bpf_refcount_acquire().

An owning pointer returned by bpf_obj_new() must continue producing a
non-NULL result without an extra check. An RCU-loaded local kptr is only
borrowed, so a checked result must load successfully while passing an
unchecked result to bpf_obj_drop() must be rejected as possibly NULL.

Use a sleepable syscall program for the borrowed cases so the explicit RCU
critical section is what permits the local kptr load. Without the verifier
fix, the unchecked case is incorrectly accepted. With it, the verifier
rejects the possibly NULL argument.

Signed-off-by: Ning Ding <dingning04@gmail.com>
[ kkd: Rewrote commit log ]
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260904084325.52250-5-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/refcounted_kptr.c
tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c