mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kery Qi <qikeyu2017@gmail.com>
To: daniel@iogearbox.net
Cc: linux-kernel@vger.kernel.org, Kery Qi <qikeyu2017@gmail.com>
Subject: [PATCH] selftests/bpf: wq: destroy skeleton on failure paths
Date: Thu,  8 Jan 2026 11:26:09 +0800	[thread overview]
Message-ID: <20260108032609.1585-1-qikeyu2017@gmail.com> (raw)

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@gmail.com>
---
 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


                 reply	other threads:[~2026-01-08  3:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260108032609.1585-1-qikeyu2017@gmail.com \
    --to=qikeyu2017@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®