[PATCH] selftests/bpf: wq: destroy skeleton on failure paths

From: Kery Qi
Date: Wed Jan 07 2026 - 22:26:23 EST


serial_test_wq() opens and loads a wq skeleton and then attaches it.
If wq__attach() fails, the test returns early and skips wq__destroy(),
leaking the skeleton resources.

Fix by routing error exits through a common cleanup path and always
destroying the skeleton when it was created.

This is the same class of bug as the earlier skeleton leak fix
(CVE-2022-3532), but in tools/testing/selftests/bpf/prog_tests/wq.c.

Signed-off-by: Kery Qi <qikeyu2017@xxxxxxxxx>
---
tools/testing/selftests/bpf/prog_tests/wq.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c
index 15c67d23128b..1dcdeda84853 100644
--- a/tools/testing/selftests/bpf/prog_tests/wq.c
+++ b/tools/testing/selftests/bpf/prog_tests/wq.c
@@ -21,7 +21,7 @@ void serial_test_wq(void)

err = wq__attach(wq_skel);
if (!ASSERT_OK(err, "wq_attach"))
- return;
+ goto clean_up

prog_fd = bpf_program__fd(wq_skel->progs.test_syscall_array_sleepable);
err = bpf_prog_test_run_opts(prog_fd, &topts);
@@ -31,7 +31,10 @@ void serial_test_wq(void)
usleep(50); /* 10 usecs should be enough, but give it extra */

ASSERT_EQ(wq_skel->bss->ok_sleepable, (1 << 1), "ok_sleepable");
- wq__destroy(wq_skel);
+
+clean_up:
+ if (wq_skel)
+ wq__destroy(wq_skel);
}

void serial_test_failures_wq(void)
--
2.34.1