Commit ee6154e1 authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by David S. Miller

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: 278b2083 ("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: default avatarNikolay Aleksandrov <nikolay@redhat.com>
Acked-by: default avatarVeaceslav Falico <vfalico@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e5fe0cd4
...@@ -1659,9 +1659,6 @@ static int __bond_release_one(struct net_device *bond_dev, ...@@ -1659,9 +1659,6 @@ static int __bond_release_one(struct net_device *bond_dev,
return -EINVAL; return -EINVAL;
} }
/* release the slave from its bond */
bond->slave_cnt--;
bond_sysfs_slave_del(slave); bond_sysfs_slave_del(slave);
bond_upper_dev_unlink(bond_dev, slave_dev); bond_upper_dev_unlink(bond_dev, slave_dev);
...@@ -1743,6 +1740,7 @@ static int __bond_release_one(struct net_device *bond_dev, ...@@ -1743,6 +1740,7 @@ static int __bond_release_one(struct net_device *bond_dev,
unblock_netpoll_tx(); unblock_netpoll_tx();
synchronize_rcu(); synchronize_rcu();
bond->slave_cnt--;
if (!bond_has_slaves(bond)) { if (!bond_has_slaves(bond)) {
call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev); call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment