selftests/bpf: Exercise double release in cpumask failure test
Subsystems (3)
PATCH v2 1/1 selftests/bpf: Exercise double release in cpumask failure test
From: Tianyi Chen <[email protected]>
create_cpumask() can return NULL, but test_alloc_double_release does not check its result before releasing it. The expected NULL-pointer diagnostic allows the test to pass when the first release is rejected, without checking the second release at all. Removing the second call still produces the same expected rejection.
Return when creation fails and expect the release-ownership diagnostic. This makes the verifier accept the first release and reject the second use of the invalidated reference.
---
Changes in v2:
- Rebase onto current bpf/master; the test logic is unchanged.
- Keep validation details outside the commit description.
Validation: all 36 cpumask subtests passed, including test_alloc_double_release, in an x86-64 KVM guest running the rebuilt bpf/master kernel (Linux 7.3.0-rc2), with LLVM 20-built selftests. There were no skips or failures.
The v1 CI PR expired after repeated "Patch is empty" reports without conflicting hunks. This patch applies cleanly to the current tree and is sent in a new thread with git format-patch and git send-email.
v1: https://lore.kernel.org/r/[email protected]
tools/testing/selftests/bpf/progs/cpumask_failure.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/cpumask_failure.c +3 -1
@@ -45,12 +45,14 @@ int BPF_PROG(test_alloc_no_release, struct task_struct *task, u64 clone_flags) } SEC("tp_btf/task_newtask") -__failure __msg("NULL pointer passed to trusted R1") +__failure __msg("release kfunc bpf_cpumask_release expects referenced PTR_TO_BTF_ID passed to R1") int BPF_PROG(test_alloc_double_release, struct task_struct *task, u64 clone_flags) {struct bpf_cpumask *cpumask; cpumask =create_cpumask (); +if (!cpumask) +return 0 ;/* cpumask is released twice. */ bpf_cpumask_release (cpumask);
base-commit: 15071f2a1263e82150c77eeb1e94dbfc31950a8e
Signature · 1 line
2.55.0