Skip to content

Commit b109398

Browse files
committed
Merge branch 'bonding-fix'
Jussi Maki says: ==================== bonding: Fix negative jump count reported by syzbot This patch set fixes a negative jump count warning encountered by syzbot [1] and extends the tests to cover nested bonding devices. [1]: https://lore.kernel.org/lkml/[email protected]/ ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e0b6417 + 4a9c93d commit b109398

File tree

2 files changed

+69
-16
lines changed

2 files changed

+69
-16
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
21692169
res = -EOPNOTSUPP;
21702170
goto err_sysfs_del;
21712171
}
2172-
} else {
2172+
} else if (bond->xdp_prog) {
21732173
struct netdev_bpf xdp = {
21742174
.command = XDP_SETUP_PROG,
21752175
.flags = 0,
@@ -5224,13 +5224,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
52245224
bpf_prog_inc(prog);
52255225
}
52265226

5227-
if (old_prog)
5228-
bpf_prog_put(old_prog);
5229-
5230-
if (prog)
5227+
if (prog) {
52315228
static_branch_inc(&bpf_master_redirect_enabled_key);
5232-
else
5229+
} else if (old_prog) {
5230+
bpf_prog_put(old_prog);
52335231
static_branch_dec(&bpf_master_redirect_enabled_key);
5232+
}
52345233

52355234
return 0;
52365235

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

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
384384
{
385385
struct bpf_link *link = NULL;
386386
struct bpf_link *link2 = NULL;
387-
int veth, bond;
388-
int err;
387+
int veth, bond, err;
389388

390389
if (!ASSERT_OK(system("ip link add veth type veth"), "add veth"))
391390
goto out;
@@ -399,22 +398,18 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
399398
if (!ASSERT_GE(bond, 0, "if_nametoindex bond"))
400399
goto out;
401400

402-
/* enslaving with a XDP program loaded fails */
401+
/* enslaving with a XDP program loaded is allowed */
403402
link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
404403
if (!ASSERT_OK_PTR(link, "attach program to veth"))
405404
goto out;
406405

407406
err = system("ip link set veth master bond");
408-
if (!ASSERT_NEQ(err, 0, "attaching slave with xdp program expected to fail"))
407+
if (!ASSERT_OK(err, "set veth master"))
409408
goto out;
410409

411410
bpf_link__destroy(link);
412411
link = NULL;
413412

414-
err = system("ip link set veth master bond");
415-
if (!ASSERT_OK(err, "set veth master"))
416-
goto out;
417-
418413
/* attaching to slave when master has no program is allowed */
419414
link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
420415
if (!ASSERT_OK_PTR(link, "attach program to slave when enslaved"))
@@ -434,15 +429,71 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
434429
goto out;
435430

436431
/* attaching to slave not allowed when master has program loaded */
437-
link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
438-
ASSERT_ERR_PTR(link2, "attach program to slave when master has program");
432+
link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
433+
if (!ASSERT_ERR_PTR(link2, "attach program to slave when master has program"))
434+
goto out;
435+
436+
bpf_link__destroy(link);
437+
link = NULL;
438+
439+
/* test program unwinding with a non-XDP slave */
440+
if (!ASSERT_OK(system("ip link add vxlan type vxlan id 1 remote 1.2.3.4 dstport 0 dev lo"),
441+
"add vxlan"))
442+
goto out;
443+
444+
err = system("ip link set vxlan master bond");
445+
if (!ASSERT_OK(err, "set vxlan master"))
446+
goto out;
447+
448+
/* attaching not allowed when one slave does not support XDP */
449+
link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
450+
if (!ASSERT_ERR_PTR(link, "attach program to master when slave does not support XDP"))
451+
goto out;
439452

440453
out:
441454
bpf_link__destroy(link);
442455
bpf_link__destroy(link2);
443456

444457
system("ip link del veth");
445458
system("ip link del bond");
459+
system("ip link del vxlan");
460+
}
461+
462+
/* Test with nested bonding devices to catch issue with negative jump label count */
463+
static void test_xdp_bonding_nested(struct skeletons *skeletons)
464+
{
465+
struct bpf_link *link = NULL;
466+
int bond, err;
467+
468+
if (!ASSERT_OK(system("ip link add bond type bond"), "add bond"))
469+
goto out;
470+
471+
bond = if_nametoindex("bond");
472+
if (!ASSERT_GE(bond, 0, "if_nametoindex bond"))
473+
goto out;
474+
475+
if (!ASSERT_OK(system("ip link add bond_nest1 type bond"), "add bond_nest1"))
476+
goto out;
477+
478+
err = system("ip link set bond_nest1 master bond");
479+
if (!ASSERT_OK(err, "set bond_nest1 master"))
480+
goto out;
481+
482+
if (!ASSERT_OK(system("ip link add bond_nest2 type bond"), "add bond_nest1"))
483+
goto out;
484+
485+
err = system("ip link set bond_nest2 master bond_nest1");
486+
if (!ASSERT_OK(err, "set bond_nest2 master"))
487+
goto out;
488+
489+
link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
490+
ASSERT_OK_PTR(link, "attach program to master");
491+
492+
out:
493+
bpf_link__destroy(link);
494+
system("ip link del bond");
495+
system("ip link del bond_nest1");
496+
system("ip link del bond_nest2");
446497
}
447498

448499
static int libbpf_debug_print(enum libbpf_print_level level,
@@ -496,6 +547,9 @@ void test_xdp_bonding(void)
496547
if (test__start_subtest("xdp_bonding_attach"))
497548
test_xdp_bonding_attach(&skeletons);
498549

550+
if (test__start_subtest("xdp_bonding_nested"))
551+
test_xdp_bonding_nested(&skeletons);
552+
499553
for (i = 0; i < ARRAY_SIZE(bond_test_cases); i++) {
500554
struct bond_test_case *test_case = &bond_test_cases[i];
501555

0 commit comments

Comments
 (0)