Skip to content

Commit c721d8f

Browse files
TropicaoAlexei Starovoitov
authored andcommitted
selftests/bpf: ensure proper root namespace cleanup when test fail
serial_test_flow_dissector_namespace manipulates both the root net namespace and a dedicated non-root net namespace. If for some reason a program attach on root namespace succeeds while it was expected to fail, the unexpected program will remain attached to the root namespace, possibly affecting other runs or even other tests in the same run. Fix undesired test failure side effect by explicitly detaching programs on failing tests expecting attach to fail. As a side effect of this change, do not test errno value if the tested operation do not fail. Fixes: 284ed00a59dd ("selftests/bpf: migrate flow_dissector namespace exclusivity test") Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 3bfb49d commit c721d8f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,14 @@ void serial_test_flow_dissector_namespace(void)
525525
ns = open_netns(TEST_NS);
526526
if (!ASSERT_OK_PTR(ns, "enter non-root net namespace"))
527527
goto out_clean_ns;
528-
529528
err = bpf_prog_attach(prog_fd, 0, BPF_FLOW_DISSECTOR, 0);
529+
if (!ASSERT_ERR(err,
530+
"refuse new flow dissector in non-root net namespace"))
531+
bpf_prog_detach2(prog_fd, 0, BPF_FLOW_DISSECTOR);
532+
else
533+
ASSERT_EQ(errno, EEXIST,
534+
"refused because of already attached prog");
530535
close_netns(ns);
531-
ASSERT_ERR(err, "refuse new flow dissector in non-root net namespace");
532-
ASSERT_EQ(errno, EEXIST, "refused because of already attached prog");
533536

534537
/* If no flow dissector is attached to the root namespace, we must
535538
* be able to attach one to a non-root net namespace
@@ -545,8 +548,11 @@ void serial_test_flow_dissector_namespace(void)
545548
* a flow dissector to root namespace must fail
546549
*/
547550
err = bpf_prog_attach(prog_fd, 0, BPF_FLOW_DISSECTOR, 0);
548-
ASSERT_ERR(err, "refuse new flow dissector on root namespace");
549-
ASSERT_EQ(errno, EEXIST, "refused because of already attached prog");
551+
if (!ASSERT_ERR(err, "refuse new flow dissector on root namespace"))
552+
bpf_prog_detach2(prog_fd, 0, BPF_FLOW_DISSECTOR);
553+
else
554+
ASSERT_EQ(errno, EEXIST,
555+
"refused because of already attached prog");
550556

551557
ns = open_netns(TEST_NS);
552558
bpf_prog_detach2(prog_fd, 0, BPF_FLOW_DISSECTOR);

0 commit comments

Comments
 (0)