BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v2] selftests/bpf: Fix freplace_link segfault in tailcalls prog test
@ 2025-01-22  2:28 Tengda Wu
  2025-01-22  2:43 ` Leon Hwang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tengda Wu @ 2025-01-22  2:28 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	hffilwlqm, leon.hwang

There are two bpf_link__destroy(freplace_link) calls in
test_tailcall_bpf2bpf_freplace(). After the first bpf_link__destroy()
is called, if the following bpf_map_{update,delete}_elem() throws an
exception, it will jump to the "out" label and call bpf_link__destroy()
again, causing double free and eventually leading to a segfault.

Fix it by directly resetting freplace_link to NULL after the first
bpf_link__destroy() call.

Fixes: 021611d33e78 ("selftests/bpf: Add test to verify tailcall and freplace restrictions")
Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
---
 tools/testing/selftests/bpf/prog_tests/tailcalls.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/tailcalls.c b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
index 544144620ca6..a12fa0521ccc 100644
--- a/tools/testing/selftests/bpf/prog_tests/tailcalls.c
+++ b/tools/testing/selftests/bpf/prog_tests/tailcalls.c
@@ -1602,6 +1602,7 @@ static void test_tailcall_bpf2bpf_freplace(void)
 	err = bpf_link__destroy(freplace_link);
 	if (!ASSERT_OK(err, "destroy link"))
 		goto out;
+	freplace_link = NULL;
 
 	/* OK to update prog_array map then delete element from the map. */
 
-- 
2.34.1


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

end of thread, other threads:[~2025-02-05  1:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-22  2:28 [PATCH bpf v2] selftests/bpf: Fix freplace_link segfault in tailcalls prog test Tengda Wu
2025-01-22  2:43 ` Leon Hwang
2025-01-24 18:34 ` Andrii Nakryiko
2025-02-05  0:51   ` Tengda Wu
2025-01-24 18:40 ` 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