Skip to content

Commit 254e0e4

Browse files
Geliang TangKernel Patches Daemon
authored andcommitted
selftests/bpf: Null checks for link in bpf_tcp_ca
Run bpf_tcp_ca selftests (./test_progs -t bpf_tcp_ca) on a Loongarch platform, some "Segmentation fault" errors occur: ''' test_dctcp:PASS:bpf_dctcp__open_and_load 0 nsec test_dctcp:FAIL:bpf_map__attach_struct_ops unexpected error: -524 #29/1 bpf_tcp_ca/dctcp:FAIL test_cubic:PASS:bpf_cubic__open_and_load 0 nsec test_cubic:FAIL:bpf_map__attach_struct_ops unexpected error: -524 #29/2 bpf_tcp_ca/cubic:FAIL test_dctcp_fallback:PASS:dctcp_skel 0 nsec test_dctcp_fallback:PASS:bpf_dctcp__load 0 nsec test_dctcp_fallback:FAIL:dctcp link unexpected error: -524 #29/4 bpf_tcp_ca/dctcp_fallback:FAIL test_write_sk_pacing:PASS:open_and_load 0 nsec test_write_sk_pacing:FAIL:attach_struct_ops unexpected error: -524 #29/6 bpf_tcp_ca/write_sk_pacing:FAIL test_update_ca:PASS:open 0 nsec test_update_ca:FAIL:attach_struct_ops unexpected error: -524 settcpca:FAIL:setsockopt unexpected setsockopt: \ actual -1 == expected -1 (network_helpers.c:99: errno: No such file or directory) \ Failed to call post_socket_cb start_test:FAIL:start_server_str unexpected start_server_str: \ actual -1 == expected -1 test_update_ca:FAIL:ca1_ca1_cnt unexpected ca1_ca1_cnt: \ actual 0 <= expected 0 #29/9 bpf_tcp_ca/update_ca:FAIL #29 bpf_tcp_ca:FAIL Caught signal #11! Stack trace: ./test_progs(crash_handler+0x28)[0x5555567ed91c] linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7ffffee408b0] ./test_progs(bpf_link__update_map+0x80)[0x555556824a78] ./test_progs(+0x94d68)[0x5555564c4d68] ./test_progs(test_bpf_tcp_ca+0xe8)[0x5555564c6a88] ./test_progs(+0x3bde54)[0x5555567ede54] ./test_progs(main+0x61c)[0x5555567efd54] /usr/lib64/libc.so.6(+0x22208)[0x7ffff2aaa208] /usr/lib64/libc.so.6(__libc_start_main+0xac)[0x7ffff2aaa30c] ./test_progs(_start+0x48)[0x55555646bca8] Segmentation fault ''' This is because "link" returned by bpf_map__attach_struct_ops() is NULL in this case. test_progs crashs when this NULL link passes to bpf_link__update_map(). This patch adds NULL checks for all links in bpf_tcp_ca to fix these errors. If "link" is NULL, goto the newly added label "err" to destroy the skel. v2: - use "goto err" instead of "return" as Eduard suggested. Signed-off-by: Geliang Tang <[email protected]>
1 parent d23ee84 commit 254e0e4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ static void test_update_ca(void)
407407
return;
408408

409409
link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
410-
ASSERT_OK_PTR(link, "attach_struct_ops");
410+
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
411+
goto err;
411412

412413
do_test(&opts);
413414
saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -421,6 +422,7 @@ static void test_update_ca(void)
421422
ASSERT_GT(skel->bss->ca2_cnt, 0, "ca2_ca2_cnt");
422423

423424
bpf_link__destroy(link);
425+
err:
424426
tcp_ca_update__destroy(skel);
425427
}
426428

@@ -443,7 +445,8 @@ static void test_update_wrong(void)
443445
return;
444446

445447
link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
446-
ASSERT_OK_PTR(link, "attach_struct_ops");
448+
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
449+
goto err;
447450

448451
do_test(&opts);
449452
saved_ca1_cnt = skel->bss->ca1_cnt;
@@ -456,6 +459,7 @@ static void test_update_wrong(void)
456459
ASSERT_GT(skel->bss->ca1_cnt, saved_ca1_cnt, "ca2_ca1_cnt");
457460

458461
bpf_link__destroy(link);
462+
err:
459463
tcp_ca_update__destroy(skel);
460464
}
461465

@@ -480,7 +484,8 @@ static void test_mixed_links(void)
480484
ASSERT_OK_PTR(link_nl, "attach_struct_ops_nl");
481485

482486
link = bpf_map__attach_struct_ops(skel->maps.ca_update_1);
483-
ASSERT_OK_PTR(link, "attach_struct_ops");
487+
if (!ASSERT_OK_PTR(link, "attach_struct_ops"))
488+
goto err;
484489

485490
do_test(&opts);
486491
ASSERT_GT(skel->bss->ca1_cnt, 0, "ca1_ca1_cnt");
@@ -489,6 +494,7 @@ static void test_mixed_links(void)
489494
ASSERT_ERR(err, "update_map");
490495

491496
bpf_link__destroy(link);
497+
err:
492498
bpf_link__destroy(link_nl);
493499
tcp_ca_update__destroy(skel);
494500
}
@@ -532,7 +538,8 @@ static void test_link_replace(void)
532538
bpf_link__destroy(link);
533539

534540
link = bpf_map__attach_struct_ops(skel->maps.ca_update_2);
535-
ASSERT_OK_PTR(link, "attach_struct_ops_2nd");
541+
if (!ASSERT_OK_PTR(link, "attach_struct_ops_2nd"))
542+
goto err;
536543

537544
/* BPF_F_REPLACE with a wrong old map Fd. It should fail!
538545
*
@@ -555,6 +562,7 @@ static void test_link_replace(void)
555562

556563
bpf_link__destroy(link);
557564

565+
err:
558566
tcp_ca_update__destroy(skel);
559567
}
560568

0 commit comments

Comments
 (0)