Skip to contentSkip to conversation

bonding: avoid adding slave device with IFF_MASTER flag

PATCH zhudi (J) 1 participant 1 message Jun 23, 2021

Subsystems (2)
lore
Share & tools
lore

zhudi (J)

author
#0 lore raw
Quoted 35 lines
Quoted 9 lines

From: Di Zhu <[email protected]>

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

Quoted 4 lines

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()

Quoted 6 lines

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.

I don't believe the statement just above is correct; nesting
bonds has historically been permitted, even if it is of questionable value these days. I've not tested nesting in a while, but last I recall it did function.

Leaving aside the question of whether it's really useful to nest
bonds or not, my concern with disabling this is that it will break existing configurations that currently work fine.

However, it should be possible to use netif_is_bonding_master
(which tests dev->flags & IFF_MASTER and dev->priv_flags & IFF_BONDING) to exclude IFF_MASTER devices that are not bonds (which seem to be vrf and eql), e.g.,

Quoted 6 lines
	if ((slave_dev->flags & IFF_MASTER) &&
		!netif_is_bond_master(slave_dev))
	
	Or we can just go with this patch and see if anything breaks.

	-J

Thank you for your advice, as Eric dumazet described: since there is a usage scenario
about nesting bonding, we should not break it.

Quoted 32 lines

Review

Quoted 7 lines

---
drivers/net/bonding/bond_main.c | 6 ++++++

1 file changed, 6 insertions(+)
(quoted diff) +0 -0

b/drivers/net/bonding/bond_main.c

drivers/net/bonding/bond_main.c int bond_enslave(struct net_device *bond_dev,

Quoted 4 lines

index c5a646d06102..16840c9bc00d 100644

drivers/net/bonding/bond_main.c +0 -0
@@ -1601,6 +1601,12 @@ int bond_enslave(struct net_device *bond_dev,

struct net_device *slave_dev,

drivers/net/bonding/bond_main.c int bond_enslave(struct net_device *bond_dev, · line 1606

Quoted 6 lines
drivers/net/bonding/bond_main.c +3 -0
 	int link_reporting;
 	int res = 0, i;
 
+	if (slave_dev->flags & IFF_MASTER) {
+		netdev_err(bond_dev,
+			   "Error: Device with IFF_MASTER cannot be

enslaved\n");

Quoted 9 lines
drivers/net/bonding/bond_main.c +3 -1
+		return -EPERM;
+	}
+
 	if (!bond->params.use_carrier &&
 	    slave_dev->ethtool_ops->get_link == NULL &&
 	    slave_ops->ndo_do_ioctl == NULL) {
--

2.23.0

---
-Jay Vosburgh, [email protected]