]> git.baikalelectronics.ru Git - kernel.git/commit
bonding: avoid adding slave device with IFF_MASTER flag
authorDi Zhu <zhudi21@huawei.com>
Tue, 22 Jun 2021 03:09:29 +0000 (11:09 +0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 22 Jun 2021 17:31:49 +0000 (10:31 -0700)
commit350e0f44e2cba0670b3c2a21d75a85583a635d2a
tree12ac05f9481b4f974e346878a93c6ef92da8c2ac
parent7ad49c28b62381d2f8cbd9957c09962e36ad25bc
bonding: avoid adding slave device with IFF_MASTER flag

The following steps will definitely cause the kernel to crash:
ip link add vrf1 type vrf table 1
modprobe bonding.ko max_bonds=1
echo "+vrf1" >/sys/class/net/bond0/bonding/slaves
rmmod bonding

The root cause is that: When the VRF is added to the slave device,
it will fail, and some cleaning work will be done. because VRF device
has IFF_MASTER flag, cleanup process  will not clear the IFF_BONDING flag.
Then, when we unload the bonding module, unregister_netdevice_notifier()
will treat the VRF device as a bond master device and treat netdev_priv()
as struct bonding{} which actually is struct net_vrf{}.

By analyzing the processing logic of bond_enslave(), it seems that
it is not allowed to add the slave device with the IFF_MASTER flag, so
we need to add a code check for this situation.

Signed-off-by: Di Zhu <zhudi21@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_main.c