Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot
@ 2021-09-06  8:56 Jussi Maki
  2021-09-06  8:56 ` [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding Jussi Maki
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jussi Maki @ 2021-09-06  8:56 UTC (permalink / raw)
  To: netdev
  Cc: ardb, jbaron, peterz, rostedt, jpoimboe, Daniel Borkmann, Jussi Maki

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/0000000000000a9f3605cb1d2455@google.com/

Jussi Maki (2):
  bonding: Fix negative jump label count on nested bonding
  selftests/bpf: Extend XDP bonding tests with unwind and nesting

 drivers/net/bonding/bond_main.c               | 11 ++-
 .../selftests/bpf/prog_tests/xdp_bonding.c    | 74 ++++++++++++++++---
 2 files changed, 69 insertions(+), 16 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding
  2021-09-06  8:56 [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot Jussi Maki
@ 2021-09-06  8:56 ` Jussi Maki
  2021-09-06  8:56 ` [PATCH net 2/2] selftests/bpf: Test XDP bonding nest and unwind Jussi Maki
  2021-09-06 12:24 ` [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jussi Maki @ 2021-09-06  8:56 UTC (permalink / raw)
  To: netdev
  Cc: ardb, jbaron, peterz, rostedt, jpoimboe, Daniel Borkmann,
	Jussi Maki, syzbot+30622fb04ddd72a4d167

With nested bonding devices the nested bond device's ndo_bpf was
called without a program causing it to decrement the static key
without a prior increment leading to negative count.

Fix the issue by 1) only calling slave's ndo_bpf when there's a
program to be loaded and 2) only decrement the count when a program
is unloaded.

Fixes: 9e2ee5c7e7c3 ("net, bonding: Add XDP support to the bonding driver")
Reported-by: syzbot+30622fb04ddd72a4d167@syzkaller.appspotmail.com
Signed-off-by: Jussi Maki <joamaki@gmail.com>
---
 drivers/net/bonding/bond_main.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b0966e733926..ae155b284f94 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2169,7 +2169,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 			res = -EOPNOTSUPP;
 			goto err_sysfs_del;
 		}
-	} else {
+	} else if (bond->xdp_prog) {
 		struct netdev_bpf xdp = {
 			.command = XDP_SETUP_PROG,
 			.flags   = 0,
@@ -5224,13 +5224,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 			bpf_prog_inc(prog);
 	}
 
-	if (old_prog)
-		bpf_prog_put(old_prog);
-
-	if (prog)
+	if (prog) {
 		static_branch_inc(&bpf_master_redirect_enabled_key);
-	else
+	} else if (old_prog) {
+		bpf_prog_put(old_prog);
 		static_branch_dec(&bpf_master_redirect_enabled_key);
+	}
 
 	return 0;
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net 2/2] selftests/bpf: Test XDP bonding nest and unwind
  2021-09-06  8:56 [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot Jussi Maki
  2021-09-06  8:56 ` [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding Jussi Maki
@ 2021-09-06  8:56 ` Jussi Maki
  2021-09-06 12:24 ` [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jussi Maki @ 2021-09-06  8:56 UTC (permalink / raw)
  To: netdev
  Cc: ardb, jbaron, peterz, rostedt, jpoimboe, Daniel Borkmann, Jussi Maki

Modify the test to check that enslaving a bond slave with a XDP program
is now allowed.

Extend attach test to exercise the program unwinding in bond_xdp_set and
add a new test for loading XDP program on doubly nested bond device to
verify that static key incr/decr is correct.

Signed-off-by: Jussi Maki <joamaki@gmail.com>
---
 .../selftests/bpf/prog_tests/xdp_bonding.c    | 74 ++++++++++++++++---
 1 file changed, 64 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
index 370d220288a6..ad3ba81b4048 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_bonding.c
@@ -384,8 +384,7 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
 {
 	struct bpf_link *link = NULL;
 	struct bpf_link *link2 = NULL;
-	int veth, bond;
-	int err;
+	int veth, bond, err;
 
 	if (!ASSERT_OK(system("ip link add veth type veth"), "add veth"))
 		goto out;
@@ -399,22 +398,18 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
 	if (!ASSERT_GE(bond, 0, "if_nametoindex bond"))
 		goto out;
 
-	/* enslaving with a XDP program loaded fails */
+	/* enslaving with a XDP program loaded is allowed */
 	link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
 	if (!ASSERT_OK_PTR(link, "attach program to veth"))
 		goto out;
 
 	err = system("ip link set veth master bond");
-	if (!ASSERT_NEQ(err, 0, "attaching slave with xdp program expected to fail"))
+	if (!ASSERT_OK(err, "set veth master"))
 		goto out;
 
 	bpf_link__destroy(link);
 	link = NULL;
 
-	err = system("ip link set veth master bond");
-	if (!ASSERT_OK(err, "set veth master"))
-		goto out;
-
 	/* attaching to slave when master has no program is allowed */
 	link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
 	if (!ASSERT_OK_PTR(link, "attach program to slave when enslaved"))
@@ -434,8 +429,26 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
 		goto out;
 
 	/* attaching to slave not allowed when master has program loaded */
-	link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
-	ASSERT_ERR_PTR(link2, "attach program to slave when master has program");
+	link2 = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, veth);
+	if (!ASSERT_ERR_PTR(link2, "attach program to slave when master has program"))
+		goto out;
+
+	bpf_link__destroy(link);
+	link = NULL;
+
+	/* test program unwinding with a non-XDP slave */
+	if (!ASSERT_OK(system("ip link add vxlan type vxlan id 1 remote 1.2.3.4 dstport 0 dev lo"),
+		       "add vxlan"))
+		goto out;
+
+	err = system("ip link set vxlan master bond");
+	if (!ASSERT_OK(err, "set vxlan master"))
+		goto out;
+
+	/* attaching not allowed when one slave does not support XDP */
+	link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
+	if (!ASSERT_ERR_PTR(link, "attach program to master when slave does not support XDP"))
+		goto out;
 
 out:
 	bpf_link__destroy(link);
@@ -443,6 +456,44 @@ static void test_xdp_bonding_attach(struct skeletons *skeletons)
 
 	system("ip link del veth");
 	system("ip link del bond");
+	system("ip link del vxlan");
+}
+
+/* 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 *link = NULL;
+	int bond, err;
+
+	if (!ASSERT_OK(system("ip link add bond type bond"), "add bond"))
+		goto out;
+
+	bond = if_nametoindex("bond");
+	if (!ASSERT_GE(bond, 0, "if_nametoindex bond"))
+		goto out;
+
+	if (!ASSERT_OK(system("ip link add bond_nest1 type bond"), "add bond_nest1"))
+		goto out;
+
+	err = system("ip link set bond_nest1 master bond");
+	if (!ASSERT_OK(err, "set bond_nest1 master"))
+		goto out;
+
+	if (!ASSERT_OK(system("ip link add bond_nest2 type bond"), "add bond_nest1"))
+		goto out;
+
+	err = system("ip link set bond_nest2 master bond_nest1");
+	if (!ASSERT_OK(err, "set bond_nest2 master"))
+		goto out;
+
+	link = bpf_program__attach_xdp(skeletons->xdp_dummy->progs.xdp_dummy_prog, bond);
+	ASSERT_OK_PTR(link, "attach program to master");
+
+out:
+	bpf_link__destroy(link);
+	system("ip link del bond");
+	system("ip link del bond_nest1");
+	system("ip link del bond_nest2");
 }
 
 static int libbpf_debug_print(enum libbpf_print_level level,
@@ -496,6 +547,9 @@ void test_xdp_bonding(void)
 	if (test__start_subtest("xdp_bonding_attach"))
 		test_xdp_bonding_attach(&skeletons);
 
+	if (test__start_subtest("xdp_bonding_nested"))
+		test_xdp_bonding_nested(&skeletons);
+
 	for (i = 0; i < ARRAY_SIZE(bond_test_cases); i++) {
 		struct bond_test_case *test_case = &bond_test_cases[i];
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot
  2021-09-06  8:56 [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot Jussi Maki
  2021-09-06  8:56 ` [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding Jussi Maki
  2021-09-06  8:56 ` [PATCH net 2/2] selftests/bpf: Test XDP bonding nest and unwind Jussi Maki
@ 2021-09-06 12:24 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-09-06 12:24 UTC (permalink / raw)
  To: Jussi Maki; +Cc: netdev, ardb, jbaron, peterz, rostedt, jpoimboe, daniel

Hello:

This series was applied to netdev/net.git (refs/heads/master):

On Mon,  6 Sep 2021 10:56:36 +0200 you wrote:
> 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/0000000000000a9f3605cb1d2455@google.com/
> 
> Jussi Maki (2):
>   bonding: Fix negative jump label count on nested bonding
>   selftests/bpf: Extend XDP bonding tests with unwind and nesting
> 
> [...]

Here is the summary with links:
  - [net,1/2] bonding: Fix negative jump label count on nested bonding
    https://git.kernel.org/netdev/net/c/6d5f1ef83868
  - [net,2/2] selftests/bpf: Test XDP bonding nest and unwind
    https://git.kernel.org/netdev/net/c/4a9c93dc47de

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-06 12:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06  8:56 [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot Jussi Maki
2021-09-06  8:56 ` [PATCH net 1/2] bonding: Fix negative jump label count on nested bonding Jussi Maki
2021-09-06  8:56 ` [PATCH net 2/2] selftests/bpf: Test XDP bonding nest and unwind Jussi Maki
2021-09-06 12:24 ` [PATCH net 0/2] bonding: Fix negative jump count reported by syzbot patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).