Skip to contentSkip to conversation

selftests/bpf: wq: destroy skeleton on failure paths

PATCH New Kery Qi 1 participant 1 message Jan 8

Subsystems (3)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 selftests/bpf: wq: destroy skeleton on failure paths

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.

---
 tools/testing/selftests/bpf/prog_tests/wq.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/wq.c +5 -2
index 15c67d23128b..1dcdeda84853 100644
@@ -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)
Signature · 1 line
2.34.1