From: Ning Ding <dingning04@gmail.com>
To: bpf@vger.kernel.org
Cc: Ning Ding <dingning04@gmail.com>
Subject: [PATCH bpf-next v2 0/2] bpf: Invalidate RCU pointers after final spin unlock
Date: Mon, 3 Aug 2026 04:26:07 -0700 [thread overview]
Message-ID: <20260803112615.3362122-1-dingning04@gmail.com> (raw)
In a sleepable BPF program, a spin lock can provide the only RCU protection
for a kptr. The final spin unlock ends that protection, but the verifier
leaves the pointer valid. Another CPU can then free the object before the
pointer is used. A capability-limited runtime PoC triggered a
KASAN-confirmed task_struct use-after-free.
Patch 1 invalidates RCU-protected pointers only when an unlock leaves the
final RCU-protected context. Patch 2 adds a negative sleepable test and
positive controls for non-sleepable and explicit-RCU contexts.
Testing used fresh QEMU/KVM guests with KASAN enabled. The patched focused
test passed all three expected outcomes. The full task_kfunc test passed
all 39 subtests, and the selected RCU, refcount, and spin-lock group had no
failures.
---
v2:
- Rebase onto bpf-next commit 60781269e26c.
- Target bpf-next and split the fix from its selftests, as requested.
- Add positive controls for RCU contexts that remain valid after unlock.
v1: https://lore.kernel.org/r/20260802231248.2781334-1-dingning04@gmail.com
Ning Ding (2):
bpf: Invalidate RCU pointers after final spin unlock
selftests/bpf: Test RCU pointer invalidation after spin unlock
kernel/bpf/verifier.c | 5 ++
.../selftests/bpf/prog_tests/task_kfunc.c | 2 +
.../selftests/bpf/progs/task_kfunc_common.h | 12 +++++
.../selftests/bpf/progs/task_kfunc_failure.c | 24 ++++++++++
.../selftests/bpf/progs/task_kfunc_success.c | 48 +++++++++++++++++++
5 files changed, 91 insertions(+)
base-commit: 60781269e26c786de2bb93fb1e697a5c32ccee48
--
2.43.0
next reply other threads:[~2026-08-03 11:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 11:26 Ning Ding [this message]
2026-08-03 11:26 ` [PATCH bpf-next v2 1/2] bpf: Invalidate RCU pointers after final spin unlock Ning Ding
2026-08-04 9:30 ` Kumar Kartikeya Dwivedi
2026-08-03 11:26 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test RCU pointer invalidation after " Ning Ding
2026-08-04 9:40 ` [PATCH bpf-next v2 0/2] bpf: Invalidate RCU pointers after final " patchwork-bot+netdevbpf
2026-08-04 10:50 ` Puranjay Mohan
2026-08-04 16:28 ` Paul E. McKenney
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=20260803112615.3362122-1-dingning04@gmail.com \
--to=dingning04@gmail.com \
--cc=bpf@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