linux/tools/testing/selftests
Kumar Kartikeya Dwivedi bfc888f045
bpf: Bound ownership depth through local kptrs and graph roots
Program-allocated objects can own other local objects through referenced
kptrs. bpf_obj_free_fields() follows those pointers through
__bpf_obj_drop_impl() synchronously, before the object storage is freed
through RCU. A self-referential local kptr type therefore permits arbitrarily
deep object chains, and dropping the head can exhaust the kernel stack.
Long acyclic type chains have the same problem.

btf_check_and_fixup_fields() still assumes referenced kptrs only point to
kernel types and checks ownership through list and rbtree roots only. Its
existing rule is sufficient for graph-only cycles: the target of each graph
edge must contain a node, so every type in a cycle has both a root and a
node. The rule rejects such a type owning another root, breaking every
cycle. It also limits graph-only chains to three types, or two if the first
type contains a node, and conservatively rejects longer acyclic chains.
The missing local-kptr edges, rather than a missed graph-only cycle, are the
bug introduced by support for bpf_kptr_xchg() into local kptrs.

Replace that restriction with one bounded ownership walk covering graph
roots and local referenced kptrs. Run it after all BTF records have been
fixed up, reject cycles and paths deeper than eight record-bearing types,
and cache each type's suffix depth while checking it against the remaining
budget. This also permits the longer acyclic graph-only layouts rejected
by the old rule; update their existing BTF tests accordingly.

Keep the bound independent of MAX_CALL_FRAMES because recursive destruction
can run below a BPF call chain. A plain local pointee without special-field
metadata adds only a final non-recursing drop. Non-owning kptrs and
kernel-BTF kptrs do not recurse through local records and remain outside the
walk. Include local percpu-kptr edges too, although allocation of percpu
objects with special fields is currently forbidden, so that relaxing that
restriction cannot bypass the ownership bound.

btf_check_and_fixup_fields() continues to initialize graph_root.value_rec,
including for separately allocated map records. The ownership relationships
belong to immutable program BTF and only need validation at BTF load time.

Fixes: b0966c7245 ("bpf: Support bpf_kptr_xchg into local kptr")
Reported-by: Nicholas Carlini <npc@anthropic.com>
Suggested-by: Nicholas Carlini <npc@anthropic.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20260914132444.2564218-2-memxor@gmail.com
2026-09-19 05:26:43 +00:00
..
acct selftests/acct: share netlink helpers 2026-08-03 21:10:14 -07:00
alloc_tag kselftest: alloc_tag: extend the allocinfo ioctl kselftest 2026-08-24 18:43:13 -07:00
alsa selftests/alsa: Fix the step check for INTEGER controls 2026-09-03 18:07:41 +02:00
amd-pstate
arm64 selftests/arm64: Add MTE test config fragment 2026-08-27 14:18:39 +00:00
bpf bpf: Bound ownership depth through local kptrs and graph roots 2026-09-19 05:26:43 +00:00
breakpoints selftests: fix ARCH normalization to handle command-line argument 2026-03-27 21:19:44 -07:00
cachestat
capabilities
cgroup cgroup: Fixes for v7.3-rc1 2026-08-31 14:20:32 -07:00
clone3 selftests/clone3: fix wild pointer access of getline due to missing init 2026-07-28 17:37:33 -07:00
connector
core
coredump selftests: check pidfd_info->coredump_code correctness 2026-03-23 16:29:15 +01:00
cpu-hotplug selftests/cpu-hotplug: Fix check for cpu hotplug not supported 2026-03-31 16:07:19 -06:00
cpufreq kselftest: cpufreq: Backup and restore governor for sptests 2026-07-22 21:56:44 +02:00
damon selftests/damon: check correct path in ensure_file() not_exist case 2026-08-04 19:18:29 -07:00
dax selftests/dax: add dax/kmem hotplug sysfs regression test 2026-08-06 18:57:00 -07:00
devices
dm-verity
dmabuf-heaps selftests: dmabuf-heaps: add fd-leak-on-EFAULT regression test 2026-08-24 14:21:55 +02:00
drivers Char/Misc/IIO/etc driver update for 7.3-rc1 2026-08-25 09:38:50 -07:00
dt
efivarfs
exec selftests/exec: test the pre-opened interpreter limit 2026-08-03 23:36:18 +02:00
fchmodat2 selftests/fchmodat2: use ksft_finished() 2026-03-27 21:19:37 -07:00
filelock kselftest/filelock: add a .gitignore file 2026-05-28 21:24:44 -07:00
filesystems fuse update for 7.3 2026-08-25 07:59:44 -07:00
firmware
fpu
ftrace Probes updates for v7.3: 2026-08-20 15:11:52 -07:00
futex selftests/futex: Give circular-list nodes static storage 2026-07-20 21:03:19 +02:00
gpio selftests: gpio: add gpio-cdev-uaf to .gitignore 2026-07-08 09:45:43 +02:00
hid selftests/hid: prepare test_rdesc_fixup_get_data_overflow for the new verifier 2026-09-01 16:08:28 +02:00
ia64
intel_pstate
iommu iommufd/selftest: Add invalidation entry_num and entry_len boundary tests 2026-06-12 10:44:44 -03:00
ipc selftests: ipc: change operation not supported error number 2026-08-03 21:10:17 -07:00
ir
kcmp
kexec
kho selftests: kho: test with deferred struct page init 2026-06-01 02:31:37 +03:00
kmod
kselftest selftests: Fix duplicated test number reporting 2026-04-17 11:29:03 -06:00
kselftest_harness selftests: harness: Validate intermixing of kselftest and harness functionality 2026-03-31 13:48:34 -06:00
kvm KVM/arm64 changes for 7.3 2026-08-24 12:42:07 -04:00
landlock selftests/landlock: Add landlock_enforce_domain trace tests 2026-08-17 10:17:19 +02:00
lib
livepatch selftests/livepatch: update test-ftrace.sh for deprecated ftrace_enabled 2026-08-10 21:21:18 -04:00
liveupdate selftests/liveupdate: Move luo_test_utils.* into a reusable library 2026-07-26 11:28:41 +03:00
lkdtm selftests/lkdtm: rename STACKLEAK_ERASING to KSTACK_ERASE 2026-07-15 18:08:11 -07:00
locking
lsm selftests/lsm: Fix memory leak in attr_lsm_count 2026-07-07 15:14:00 -04:00
media_tests
membarrier selftests/membarrier: Add rseq stress test for CFS throttle interactions 2026-05-05 12:50:48 +02:00
memfd selftests/memfd: remove unused variable 'sig' in fuse_test 2026-06-04 14:45:06 -07:00
memory-hotplug
mincore selftests: mincore: count file-mmap readahead on both sides 2026-08-06 18:56:55 -07:00
mm mm/secretmem: properly account locked pages 2026-09-03 10:56:10 -07:00
module
mount
mount_setattr selftests/mount_setattr: increase tmpfs size for idmapped mount tests 2026-03-17 16:59:45 +01:00
move_mount_set_group
mqueue selftests/mqueue: Fix incorrectly named file 2026-03-31 15:01:51 -06:00
mseal_system_mappings
namespaces selftests/namespaces: Fix racy pipe handshake in timens and pidns_separate 2026-08-13 12:20:42 +02:00
nci
net selftests: net: Add exception cache tests 2026-08-31 19:56:31 -07:00
nolibc tools/nolibc: add support for Alpha 2026-08-02 09:30:55 +02:00
ntb
pci_endpoint selftests: pci_endpoint: Skip BAR subrange test on -ENOSPC 2026-04-08 14:41:39 -05:00
pcie_bwctrl
perf_events selftests/perf_events: fix mmap() error check in sigtrap_threads 2026-05-28 21:24:49 -07:00
pid_namespace selftests/pid_namespace: compute pid_max test limits dynamically 2026-05-11 11:09:30 +02:00
pidfd selftests/pidfd: check PIDFD_THREAD survives open_by_handle_at() 2026-07-22 13:55:20 +02:00
pipe selftests/pipe: add pipe_bench microbenchmark 2026-05-28 14:33:25 +02:00
power_supply power: supply: Add PbAc, NiZn, RAM, and ZnAr support 2026-07-21 22:28:11 +02:00
powerpc selftests/powerpc: Suppress -Wmaybe-uninitialized with GCC 15 2026-04-01 09:21:04 +05:30
prctl selftests/prctl: fix non-anonymous VMA mapping in set-anon-vma-name test 2026-08-13 15:42:07 -07:00
proc mm.git review status for linus..mm-stable 2026-08-27 09:17:06 -07:00
pstore
ptp selftests: ptp: treat unsupported PHC operations as skip 2026-01-27 17:57:28 -08:00
ptrace
rcutorture torture: Allow "norm" abbreviation for "normal" 2026-05-24 09:38:59 +02:00
rdma RDMA/selftests: Add rxe_netns_names test 2026-07-26 03:11:00 -04:00
resctrl selftests/resctrl: Reduce L2 impact on CAT test 2026-05-04 18:40:02 -06:00
ring-buffer
riscv selftests/riscv: ptrace: Fix memory leak of regset_data in vector tests 2026-07-10 09:32:35 -06:00
rlimits
rseq Futex updates: 2026-08-18 15:26:35 -07:00
rtc
rust
safesetid
sched
sched_ext selftests/sched_ext: Fix flaky ddsp failure tests on busy systems 2026-08-14 12:32:23 -10:00
seccomp selftests/seccomp: Fix pointer type mismatch build error 2026-07-15 18:11:29 -07:00
sgx
signal
size
sparc64 selftests: fix ARCH normalization to handle command-line argument 2026-03-27 21:19:44 -07:00
splice
static_keys
sync
syscall_user_dispatch syscall_user_dispatch: Make it configurable in Kconfig 2026-07-08 10:22:00 +02:00
sysctl
tc-testing selftests: tc-testing: add u32 node ID pool exhaustion test 2026-08-31 16:07:33 -07:00
tdx
thermal/intel selftests: fix ARCH normalization to handle command-line argument 2026-03-27 21:19:44 -07:00
timens
timers selftests: timers: nsleep-lat: Check all calls to clock_nanosleep() and clock_gettime() 2026-08-11 18:11:21 +02:00
tmpfs
tpm2
tty
turbostat
ublk selftests: ublk: add SET_PARAMS validation test 2026-08-15 17:17:11 -06:00
uevent selftests/uevent: increase __UEVENT_BUFFER_SIZE to avoid ENOBUFS on busy systems 2026-06-17 15:37:46 -07:00
user_events selftests/user_events: Wait for deferred event teardown after unregister 2026-07-08 09:33:22 -04:00
vDSO selftests: vDSO: vdso_test_correctness: Add a test for time() 2026-03-11 15:23:24 +01:00
verification selftests/verification: Add selftests for deadline and stall monitors 2026-07-31 16:27:46 +02:00
vfio vfio: selftests: Retry on EAGAIN during device reset 2026-08-10 13:24:40 -06:00
vsock selftests/vsock: skip vng setsid workaround on >= 1.41 2026-06-15 12:52:01 -07:00
watchdog
wireguard sysctl: remove CONFIG_PROC_SYSCTL, it just mirrors CONFIG_SYSCTL 2026-08-05 15:28:23 +02:00
x86 selftests/x86: Add shadow stack uprobe CALL test 2026-07-02 13:21:49 +02:00
zram selftests/zram: fix kernel_gte() for POSIX sh 2026-07-30 07:55:37 -06:00
.gitignore
clock-helpers.h selftests: Add clock-helpers.h 2026-08-11 18:11:20 +02:00
gen_kselftest_tar.sh
kselftest_deps.sh
kselftest_harness.h selftests: harness: Mark test fixture objects __maybe_unused 2026-08-12 12:00:05 -06:00
kselftest_install.sh
kselftest_module.h
kselftest.h linux_kselftest-next-7.2-rc1 2026-06-16 16:49:07 +05:30
lib.mk
Makefile mm.git review status for linus..mm-stable 2026-08-27 09:17:06 -07:00
run_kselftest.sh selftests/run_kselftest.sh: Allow choosing per-test log directory 2026-04-13 11:05:39 -06:00