BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Guard link cleanup in fexit_bpf2bpf
@ 2026-09-17  9:39 Zhixing Chen
  2026-09-17 10:34 ` bot+bpf-ci
  2026-09-21 21:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Zhixing Chen @ 2026-09-17  9:39 UTC (permalink / raw)
  To: bpf; +Cc: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai, Zhixing Chen

test_fexit_bpf2bpf_common() can jump to the common cleanup path before
the link array is allocated, for example if bpf_prog_get_info_by_fd()
fails. The cleanup loop still indexes link[i] unconditionally, which can
dereference a NULL pointer and hide the original failure.

Guard the loop so the test reports the original failure instead.

Signed-off-by: Zhixing Chen <running910@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
index 6262c81cdaa9..d2f2dcc0f2e1 100644
--- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
@@ -164,8 +164,10 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
 		goto close_prog;
 
 close_prog:
-	for (i = 0; i < prog_cnt; i++)
-		bpf_link__destroy(link[i]);
+	if (link) {
+		for (i = 0; i < prog_cnt; i++)
+			bpf_link__destroy(link[i]);
+	}
 	bpf_object__close(obj);
 	bpf_object__close(tgt_obj);
 	free(link);

base-commit: 71b75648d1a21c0a6379741d00f41086ec95f14a
-- 
2.34.1


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

end of thread, other threads:[~2026-09-21 22:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17  9:39 [PATCH bpf-next] selftests/bpf: Guard link cleanup in fexit_bpf2bpf Zhixing Chen
2026-09-17 10:34 ` bot+bpf-ci
2026-09-21 21:30 ` 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