Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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) <alexis.lothore@bootlin.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://lore.kernel.org/r/20241128-small_flow_test_fix-v1-1-c12d45c98c59@bootlin.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Alexis Lothoré (eBPF Foundation) and committed by
Alexei Starovoitov
c721d8f8 3bfb49d7

+11 -5
+11 -5
tools/testing/selftests/bpf/prog_tests/flow_dissector.c
··· 525 525 ns = open_netns(TEST_NS); 526 526 if (!ASSERT_OK_PTR(ns, "enter non-root net namespace")) 527 527 goto out_clean_ns; 528 - 529 528 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"); 530 535 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"); 533 536 534 537 /* If no flow dissector is attached to the root namespace, we must 535 538 * be able to attach one to a non-root net namespace ··· 548 545 * a flow dissector to root namespace must fail 549 546 */ 550 547 err = bpf_prog_attach(prog_fd, 0, BPF_FLOW_DISSECTOR, 0); 551 - ASSERT_ERR(err, "refuse new flow dissector on root namespace"); 552 - ASSERT_EQ(errno, EEXIST, "refused because of already attached prog"); 548 + if (!ASSERT_ERR(err, "refuse new flow dissector on root namespace")) 549 + bpf_prog_detach2(prog_fd, 0, BPF_FLOW_DISSECTOR); 550 + else 551 + ASSERT_EQ(errno, EEXIST, 552 + "refused because of already attached prog"); 553 553 554 554 ns = open_netns(TEST_NS); 555 555 bpf_prog_detach2(prog_fd, 0, BPF_FLOW_DISSECTOR);