bonding: fix a div error caused by the slave release path
Subsystems (3)
PATCH 1/1 bonding: fix a div error caused by the slave release path
There's a bug in the slave release function which leads the transmit functions which use the bond->slave_cnt to a div by 0 because we might just have released our last slave and made slave_cnt == 0 but at the same time we may have a transmitter after the check for an empty list which will fetch it and use it in the slave id calculation.
Fix it by moving the slave_cnt after synchronize_rcu so if this was our last slave any new transmitters will see an empty slave list which is checked after rcu lock but before calling the mode transmit functions which rely on bond->slave_cnt.
--- drivers/net/bonding/bond_main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/bonding/bond_main.c +1 -3
@@ -1654,9 +1654,6 @@ static int __bond_release_one(struct net_device *bond_dev,return -EINVAL ; } -/* release the slave from its bond */ - bond->slave_cnt--; -bond_sysfs_slave_del (slave);bond_upper_dev_unlink (bond_dev, slave_dev);
@@ -1738,6 +1735,7 @@ static int __bond_release_one(struct net_device *bond_dev,unblock_netpoll_tx ();synchronize_rcu (); + bond->slave_cnt--;if (!bond_has_slaves (bond)) {call_netdevice_notifiers (NETDEV_CHANGEADDR , bond->dev);
Signature · 1 line
1.8.4.2
Quoted 10 lines · Nikolay Aleksandrov
There's a bug in the slave release function which leads the transmit functions which use the
bond->slave_cntto a div by 0 because we might just have released our last slave and madeslave_cnt== 0 but at the same time we may have a transmitter after the check for an empty list which will fetch it and use it in the slave id calculation.
Fix it by moving theslave_cntaftersynchronize_rcuso if this was our last slave any new transmitters will see an empty slave list which is checked after rcu lock but before calling the mode transmit functions which rely onbond->slave_cnt.
Quoted 8 lines
Fixes 278b208375 ("bonding: initial RCU conversion")CC Veaceslav Falico <[email protected]>CC Andy Gospodarek <[email protected]>CC Jay Vosburgh <[email protected]>CC David S. Miller <[email protected]>Signed-off-by Nikolay Aleksandrov <[email protected]>
On a side note - slave_cnt is used only for roundrobin/xor slave identification. It *might* be a good idea to remove it completely, though I can't figure out a way how to remove it without some overhead in fast path...
Quoted 29 lines
---
drivers/net/bonding/bond_main.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)drivers/net/bonding/bond_main.c +1
-3@@ -1654,9 +1654,6 @@ static int __bond_release_one(struct net_device *bond_dev,return -EINVAL ; } -/* release the slave from its bond */ - bond->slave_cnt--; -bond_sysfs_slave_del (slave);bond_upper_dev_unlink (bond_dev, slave_dev);@@ -1738,6 +1735,7 @@ static int __bond_release_one(struct net_device *bond_dev,unblock_netpoll_tx ();synchronize_rcu (); + bond->slave_cnt--;if (!bond_has_slaves (bond)) {call_netdevice_notifiers (NETDEV_CHANGEADDR , bond->dev);Signature · 1 line
1.8.4.2
From: Veaceslav Falico <[email protected]>
Date: Wed, 26 Feb 2014 14:28:54 +0100
Quoted 16 lines · Nikolay Aleksandrov
Quoted 15 lines
There's a bug in the slave release function which leads the transmit functions which use the
bond->slave_cntto a div by 0 because we might just have released our last slave and madeslave_cnt== 0 but at the same
time we may have a transmitter after the check for an empty list which will
fetch it and use it in the slave id calculation.
Fix it by moving theslave_cntaftersynchronize_rcuso if this was our
last slave any new transmitters will see an empty slave list which is checked after rcu lock but before calling the mode transmit functions which rely onbond->slave_cnt.Fixes 278b208375 ("bonding: initial RCU conversion")
Quoted 8 lines
Quoted 6 lines
CC Veaceslav Falico <[email protected]>CC Andy Gospodarek <[email protected]>CC Jay Vosburgh <[email protected]>CC David S. Miller <[email protected]>Signed-off-by Nikolay Aleksandrov <[email protected]>Acked-by Veaceslav Falico <[email protected]>
Applied, thanks.