Skip to contentSkip to conversation

bonding: initialize err for empty target lists

PATCH Applied Ruoyu Wang 7 participants 9 messages Aug 13 – Aug 18

Subsystems (3)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 bonding: initialize err for empty target lists

Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.

Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 4fb0ef585eb2 ("bonding: convert arp_ip_target to use the new option API")
---
 drivers/net/bonding/bond_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +1 -1
index 4a11572f663d31..87d92d3cce4a88 100644
@@ -220,7 +220,7 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
 	struct bonding *bond = netdev_priv(bond_dev);
 	struct bond_opt_value newval;
 	int miimon = 0;
-	int err;
+	int err = 0;
 
 	if (!data)
 		return 0;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Ruoyu Wang

Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.

Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 4fb0ef585eb2 ("bonding: convert arp_ip_target to use the new option API")
---
  drivers/net/bonding/bond_netlink.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +0 -0
index 4a11572f663d31..87d92d3cce4a88 100644

drivers/net/bonding/bond_netlink.c static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[], · line 226

Quoted 8 lines
drivers/net/bonding/bond_netlink.c +1 -1
@@ -220,7 +220,7 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
  	struct bonding *bond = netdev_priv(bond_dev);
  	struct bond_opt_value newval;
  	int miimon = 0;
-	int err;
+	int err = 0;
 
  	if (!data)
  		return 0;

Oh well, I've missed they can be empty. :)
By the way you haven't CCed the Fixes commit author (me).

Thanks,

#2 lore raw
Quoted 1 line

By the way you haven't CCed the Fixes commit author (me).

Hi Nikolay

./scripts/get_maintainer.pl drivers/net/bonding/bond_netlink.c Jay Vosburgh <[email protected]> (maintainer:BONDING DRIVER) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:BONDING DRIVER) [email protected] (open list)

You are not listed. Maybe you can submit a patch to MAINTAINERS?

Andrew

#3 lore raw
Quoted 14 lines · Andrew Lunn
Quoted 1 line

By the way you haven't CCed the Fixes commit author (me).

Hi Nikolay

./scripts/get_maintainer.pl drivers/net/bonding/bond_netlink.c Jay Vosburgh <[email protected]> (maintainer:BONDING DRIVER) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:BONDING DRIVER) [email protected] (open list)

Quoted 3 lines

You are not listed. Maybe you can submit a patch to MAINTAINERS?

Andrew

I didn't mean it as a maintainer, it is customary and good practice to email the author of the commit that introduced the regression, that is all I was trying to say.

Cheers,
Nik

#4 lore raw
Quoted 15 lines · Nikolay Aleksandrov
Quoted 14 lines · Andrew Lunn
Quoted 1 line

By the way you haven't CCed the Fixes commit author (me).

Hi Nikolay

./scripts/get_maintainer.pl drivers/net/bonding/bond_netlink.c Jay Vosburgh <[email protected]> (maintainer:BONDING DRIVER) Andrew Lunn <[email protected]> (maintainer:NETWORKING DRIVERS) "David S. Miller" <[email protected]> (maintainer:NETWORKING DRIVERS) Eric Dumazet <[email protected]> (maintainer:NETWORKING DRIVERS) Jakub Kicinski <[email protected]> (maintainer:NETWORKING DRIVERS) Paolo Abeni <[email protected]> (maintainer:NETWORKING DRIVERS) [email protected] (open list:BONDING DRIVER) [email protected] (open list)

Quoted 7 lines
Quoted 3 lines

You are not listed. Maybe you can submit a patch to MAINTAINERS?

Andrew

I didn't mean it as a maintainer, it is customary and good practice to email the author of the commit that introduced the regression, that is all I was trying to say.

Interesting:

scripts/get_maintainer.pl --help
usage: scripts/get_maintainer.pl [options] patchfile
scripts/get_maintainer.pl [options] -f file|directory
version: 0.26

MAINTAINER field selection options:
--email => print email address(es) if any
...
--fixes => for patches, add signatures of commits with 'Fixes: <commit>' (default: 1 (on))

So it should of done it, if it was run on the patch, rather than the file.

I wounder what "b4 prep --auto-to-cc" does?

Andrew

maintainer
#5 lore raw
Quoted 11 lines · On Fri, 14 Aug 2026 02:44:11 +0200 Andrew Lunn wrote:
Quoted 3 lines

I didn't mean it as a maintainer, it is customary and good practice to email the author of the commit that introduced the regression, that is all I was trying to say.

Interesting:

scripts/get_maintainer.pl --help
usage: scripts/get_maintainer.pl [options] patchfile
scripts/get_maintainer.pl [options] -f file|directory
version: 0.26

Quoted 7 lines

MAINTAINER field selection options:
--email => print email address(es) if any
...
--fixes => for patches, add signatures of commits with 'Fixes: <commit>' (default: 1 (on))

So it should of done it, if it was run on the patch, rather than the file.

FWIW it's a common mistake to run get maint on a file path. I sent a patch once to print a WARNING when paths are used. But apparently the path case has at least one important user - Linus :)

maintainer Acked-by on v1 1/1
#6 lore raw
In reply to Ruoyu Wang
Quoted 6 lines · Ruoyu Wang

Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.

Quoted 8 lines

Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 4fb0ef585eb2 ("bonding: convert arp_ip_target to use the new option API")
Quoted 20 lines

---
drivers/net/bonding/bond_netlink.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +1 -1
index 4a11572f663d31..87d92d3cce4a88 100644
@@ -220,7 +220,7 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
 	struct bonding *bond = netdev_priv(bond_dev);
 	struct bond_opt_value newval;
 	int miimon = 0;
-	int err;
+	int err = 0;
 
 	if (!data)
 		return 0;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#7 lore raw
In reply to Ruoyu Wang
Quoted 34 lines · Ruoyu Wang

Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.

Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.

This issue was found by a static analysis checker and confirmed by manual source review.

Fixes 4fb0ef585eb2 ("bonding: convert arp_ip_target to use the new option API")
---
 drivers/net/bonding/bond_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/bond_netlink.c +1 -1
index 4a11572f663d31..87d92d3cce4a88 100644
@@ -220,7 +220,7 @@ static int bond_changelink(struct net_device *bond_dev, struct nlattr *tb[],
 	struct bonding *bond = netdev_priv(bond_dev);
 	struct bond_opt_value newval;
 	int miimon = 0;
-	int err;
+	int err = 0;
 
 	if (!data)
 		return 0;
Signature · 1 line
2.51.0
#8 lore raw
In reply to Ruoyu Wang
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 13 Aug 2026 23:31:26 +0800 you wrote:

Empty NLA_NESTED attributes are valid, and bonding uses them to clear the ARP and NS target lists. When either target attribute is empty, nla_for_each_nested() does not execute, so err retains an uninitialized value before it is tested. The request can consequently return an unpredictable error after clearing the targets.

Initialize err to zero so an empty target list completes successfully. Non-empty lists still propagate errors from __bond_opt_set() unchanged.

[...]

Here is the summary with links:
- [net] bonding: initialize err for empty target lists
https://git.kernel.org/netdev/net/c/8ccc9bf9afee

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html