提交 6dc7a0ba 编写于 作者: J Jörn-Thorben Hinz 提交者: Andrii Nakryiko

selftests/bpf: Fix rare segfault in sock_fields prog test

test_sock_fields__detach() got called with a null pointer here when one
of the CHECKs or ASSERTs up to the test_sock_fields__open_and_load()
call resulted in a jump to the "done" label.

A skeletons *__detach() is not safe to call with a null pointer, though.
This led to a segfault.

Go the easy route and only call test_sock_fields__destroy() which is
null-pointer safe and includes detaching.

Came across this while looking[1] to introduce the usage of
bpf_tcp_helpers.h (included in progs/test_sock_fields.c) together with
vmlinux.h.

[1] https://lore.kernel.org/bpf/629bc069dd807d7ac646f836e9dca28bbc1108e2.camel@mailbox.tu-berlin.de/

Fixes: 8f50f16f ("selftests/bpf: Extend verifier and bpf_sock tests for dst_port loads")
Signed-off-by: NJörn-Thorben Hinz <jthinz@mailbox.tu-berlin.de>
Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
Reviewed-by: NJakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: NMartin KaFai Lau <kafai@fb.com>
Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20220621070116.307221-1-jthinz@mailbox.tu-berlin.de
上级 bb7a4257
...@@ -394,7 +394,6 @@ void serial_test_sock_fields(void) ...@@ -394,7 +394,6 @@ void serial_test_sock_fields(void)
test(); test();
done: done:
test_sock_fields__detach(skel);
test_sock_fields__destroy(skel); test_sock_fields__destroy(skel);
if (child_cg_fd >= 0) if (child_cg_fd >= 0)
close(child_cg_fd); close(child_cg_fd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册