Skip to content

Commit ee6154e

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
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. Fixes: 278b208 ("bonding: initial RCU conversion") CC: Veaceslav Falico <vfalico@redhat.com> CC: Andy Gospodarek <andy@greyhouse.net> CC: Jay Vosburgh <fubar@us.ibm.com> CC: David S. Miller <davem@davemloft.net> Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Acked-by: Veaceslav Falico <vfalico@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e5fe0cd commit ee6154e

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

drivers/net/bonding/bond_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,9 +1659,6 @@ static int __bond_release_one(struct net_device *bond_dev,
16591659
return -EINVAL;
16601660
}
16611661

1662-
/* release the slave from its bond */
1663-
bond->slave_cnt--;
1664-
16651662
bond_sysfs_slave_del(slave);
16661663

16671664
bond_upper_dev_unlink(bond_dev, slave_dev);
@@ -1743,6 +1740,7 @@ static int __bond_release_one(struct net_device *bond_dev,
17431740

17441741
unblock_netpoll_tx();
17451742
synchronize_rcu();
1743+
bond->slave_cnt--;
17461744

17471745
if (!bond_has_slaves(bond)) {
17481746
call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);

0 commit comments

Comments
 (0)