diff options
author | nikolay@redhat.com <nikolay@redhat.com> | 2013-04-11 09:18:55 +0000 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-04-11 16:01:47 -0400 |
commit | 6101391d4a381cc0c661d8765235b3cad7da09e5 (patch) | |
tree | 02a81e2e58e4fda541f1d3c64cee787bdcdf757f /drivers | |
parent | d66954a066158781ccf9c13c91d0316970fe57b6 (diff) | |
download | linux-stable-6101391d4a381cc0c661d8765235b3cad7da09e5.tar.gz linux-stable-6101391d4a381cc0c661d8765235b3cad7da09e5.tar.bz2 linux-stable-6101391d4a381cc0c661d8765235b3cad7da09e5.zip |
bonding: fix netdev event NULL pointer dereference
In commit 471cb5a33dcbd7c529684a2ac7ba4451414ee4a7 ("bonding: remove
usage of dev->master") a bug was introduced which causes a NULL pointer
dereference. If a bond device is in mode 6 (ALB) and a slave is added
it will dereference a NULL pointer in bond_slave_netdev_event().
This is because in bond_enslave we have bond_alb_init_slave() which
changes the MAC address of the slave and causes a NETDEV_CHANGEADDR.
Then we have in bond_slave_netdev_event():
struct slave *slave = bond_slave_get_rtnl(slave_dev);
struct bonding *bond = slave->bond;
bond_slave_get_rtnl() dereferences slave_dev->rx_handler_data which at
that time is NULL since netdev_rx_handler_register() is called later.
This is fixed by checking if slave is NULL before dereferencing it.
v2: Comment style changed.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/net/bonding/bond_main.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 07401a3e256b..e074c6b55517 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3168,11 +3168,20 @@ static int bond_slave_netdev_event(unsigned long event, struct net_device *slave_dev) { struct slave *slave = bond_slave_get_rtnl(slave_dev); - struct bonding *bond = slave->bond; - struct net_device *bond_dev = slave->bond->dev; + struct bonding *bond; + struct net_device *bond_dev; u32 old_speed; u8 old_duplex; + /* A netdev event can be generated while enslaving a device + * before netdev_rx_handler_register is called in which case + * slave will be NULL + */ + if (!slave) + return NOTIFY_DONE; + bond_dev = slave->bond->dev; + bond = slave->bond; + switch (event) { case NETDEV_UNREGISTER: if (bond->setup_by_slave) |