BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix map fd leak in no-BTF wq test
@ 2026-10-13  3:01 Yun Lu
  2026-10-15 16:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Yun Lu @ 2026-10-13  3:01 UTC (permalink / raw)
  To: ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, shuah
  Cc: yatsenko, bpf, linux-kselftest

From: Yun Lu <luyun@kylinos.cn>

bpf_map__reuse_fd() duplicates the supplied file descriptor instead of
taking ownership of it. test_failure_map_no_btf() closes the original
map_fd only when reuse fails, leaking it when reuse succeeds, including
when the test passes. Destroying the skeleton closes its own descriptor
but leaves the original descriptor and its map reference alive.

Close map_fd immediately after bpf_map__reuse_fd(), before checking its
return value, to release the original descriptor on both success and
failure. The skeleton retains its own descriptor for the subsequent
program load.

Fixes: bca2b74ea9a8 ("selftests/bpf: Add more bpf_wq tests")
Reported-by: Jackie Liu <liuyun01@kylinos.cn>
Signed-off-by: Yun Lu <luyun@kylinos.cn>
---
 tools/testing/selftests/bpf/prog_tests/wq.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c
index 84831eecc935..97926e35aaf2 100644
--- a/tools/testing/selftests/bpf/prog_tests/wq.c
+++ b/tools/testing/selftests/bpf/prog_tests/wq.c
@@ -64,10 +64,9 @@ static void test_failure_map_no_btf(void)
 		goto out;
 
 	err = bpf_map__reuse_fd(skel->maps.array, map_fd);
-	if (!ASSERT_OK(err, "map reuse fd")) {
-		close(map_fd);
+	close(map_fd);
+	if (!ASSERT_OK(err, "map reuse fd"))
 		goto out;
-	}
 
 	insns = bpf_program__insns(skel->progs.test_map_no_btf);
 	if (!ASSERT_OK_PTR(insns, "insns ptr"))

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix map fd leak in no-BTF wq test
  2026-10-13  3:01 [PATCH bpf-next] selftests/bpf: Fix map fd leak in no-BTF wq test Yun Lu
@ 2026-10-15 16:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-15 16:50 UTC (permalink / raw)
  To: luyun
  Cc: ast, daniel, andrii, eddyz87, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, ihor.solodrai, shuah, yatsenko, bpf,
	linux-kselftest

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Tue, 13 Oct 2026 11:01:14 +0800 you wrote:
> From: Yun Lu <luyun@kylinos.cn>
> 
> bpf_map__reuse_fd() duplicates the supplied file descriptor instead of
> taking ownership of it. test_failure_map_no_btf() closes the original
> map_fd only when reuse fails, leaking it when reuse succeeds, including
> when the test passes. Destroying the skeleton closes its own descriptor
> but leaves the original descriptor and its map reference alive.
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Fix map fd leak in no-BTF wq test
    https://git.kernel.org/bpf/bpf-next/c/d3c9ecb8765d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-15 16:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13  3:01 [PATCH bpf-next] selftests/bpf: Fix map fd leak in no-BTF wq test Yun Lu
2026-10-15 16:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox