提交 6101391d 编写于 作者: N nikolay@redhat.com 提交者: David S. Miller

bonding: fix netdev event NULL pointer dereference

In commit 471cb5a3 ("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: NNikolay Aleksandrov <nikolay@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 d66954a0
...@@ -3168,11 +3168,20 @@ static int bond_slave_netdev_event(unsigned long event, ...@@ -3168,11 +3168,20 @@ static int bond_slave_netdev_event(unsigned long event,
struct net_device *slave_dev) struct net_device *slave_dev)
{ {
struct slave *slave = bond_slave_get_rtnl(slave_dev); struct slave *slave = bond_slave_get_rtnl(slave_dev);
struct bonding *bond = slave->bond; struct bonding *bond;
struct net_device *bond_dev = slave->bond->dev; struct net_device *bond_dev;
u32 old_speed; u32 old_speed;
u8 old_duplex; 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) { switch (event) {
case NETDEV_UNREGISTER: case NETDEV_UNREGISTER:
if (bond->setup_by_slave) if (bond->setup_by_slave)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册