test_xdp_bonding_attach() already covers a flat bond both ways round:
the master is refused while a slave has a program, and a slave is
refused while the master has one. The nested test only ever checked
that attaching to the outermost master succeeds.
That left the more interesting half of the nesting untested. Only the
direct upper is consulted when deciding whether a device is already
running XDP, so with bond -> bond_nest1 -> bond_nest2 the check on
bond_nest2 looks at bond_nest1, and it only sees a program there if
bond_nest1 recorded the one it was handed. Before the preceding fix it
did not, and a second program could be attached to bond_nest2 while the
outer bond's program was already running on it.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
.../selftests/bpf/prog_tests/xdp_bonding.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
index c42488e445c2..486e0f9a2ada 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
@@ -464,8 +464,9 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
/* Test with nested bonding devices to catch issue with negative jump label count */
static void test_xdp_bonding_nested(struct skeletons *skeletons)
{
+ struct bpf_link *link2 = NULL;
struct bpf_link *link = NULL;
- int bond, err;
+ int bond, nest2, err;
if (!ASSERT_OK(system("ip link add bond type bond"), "add bond"))
goto out;@@ -488,10 +489,23 @@ static void test_xdp_bonding_nested(struct skeletons *skeletons)
if (!ASSERT_OK(err, "set bond_nest2 master"))
goto out;
+ nest2 = if_nametoindex("bond_nest2");
+ if (!ASSERT_GE(nest2, 0, "if_nametoindex bond_nest2"))
+ goto out;
+
link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
- ASSERT_OK_PTR(link, "attach program to master");
+ if (!ASSERT_OK_PTR(link, "attach program to master"))
+ goto out;
+
+ /* Attaching to a nested slave is not allowed either. Only the direct
+ * upper is consulted, so this only holds if every device the program
+ * was propagated to records it.
+ */
+ link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, nest2);
+ ASSERT_ERR_PTR(link2, "attach program to nested slave when master has program");
out:
+ bpf_link__destroy(link2);
bpf_link__destroy(link);
system("ip link del bond");
system("ip link del bond_nest1");--
2.55.0