Skip to contentSkip to conversation

core: Correct an over-stringent device loop detection.

PATCH Applied Vladislav Yasevich 5 participants 6 messages May 3, 2015 – May 4, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 core: Correct an over-stringent device loop detection.

The code in __netdev_upper_dev_link() has an over-stringent loop detection logic that actually prevents valid configurations from working correctly.

In particular, the logic returns an error if an upper device is already in the list of all upper devices for a given dev. This particular check seems to be a overzealous as it disallows perfectly valid configurations. For example:

  # ip l a link eth0 name eth0.10 type vlan id 10
  # ip l a dev br0 typ bridge
  # ip l s eth0.10 master br0
  # ip l s eth0 master br0  <--- Will fail

If you switch the last two commands (add eth0 first), then both will succeed. If after that, you remove eth0 and try to re-add it, it will fail!

It appears to be enough to simply check adj_list to keeps things safe.

I've tried stacking multiple devices multiple times in all different combinations, and either rx_handler registration prevented the stacking of the device linking cought the error.

---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index c7ba038..2c1c67f 100644
@@ -5209,7 +5209,7 @@ static int __netdev_upper_dev_link(struct net_device *dev,
 	if (__netdev_find_adj(upper_dev, dev, &upper_dev->all_adj_list.upper))
 		return -EBUSY;
 
-	if (__netdev_find_adj(dev, upper_dev, &dev->all_adj_list.upper))
+	if (__netdev_find_adj(dev, upper_dev, &dev->adj_list.upper))
 		return -EEXIST;
 
 	if (master && netdev_master_upper_dev_get(dev))
Signature · 1 line
1.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Sun, May 03, 2015 at 03:33:44AM CEST, [email protected] wrote:

The code in __netdev_upper_dev_link() has an over-stringent loop detection logic that actually prevents valid configurations from working correctly.

In particular, the logic returns an error if an upper device is already in the list of all upper devices for a given dev. This particular check seems to be a overzealous as it disallows perfectly valid configurations. For example:

 # ip l a link eth0 name eth0.10 type vlan id 10
 # ip l a dev br0 typ bridge
 # ip l s eth0.10 master br0
 # ip l s eth0 master br0  <--- Will fail

If you switch the last two commands (add eth0 first), then both will succeed. If after that, you remove eth0 and try to re-add it, it will fail!

Quoted 8 lines

It appears to be enough to simply check adj_list to keeps things safe.

I've tried stacking multiple devices multiple times in all different combinations, and either rx_handler registration prevented the stacking of the device linking cought the error.

Acked-by on v1 1/1
#2 lore raw
In reply to Vladislav Yasevich
Quoted 17 lines · Vladislav Yasevich

The code in __netdev_upper_dev_link() has an over-stringent loop detection logic that actually prevents valid configurations from working correctly.

In particular, the logic returns an error if an upper device is already in the list of all upper devices for a given dev. This particular check seems to be a overzealous as it disallows perfectly valid configurations. For example:

 # ip l a link eth0 name eth0.10 type vlan id 10
 # ip l a dev br0 typ bridge
 # ip l s eth0.10 master br0
 # ip l s eth0 master br0  <--- Will fail

If you switch the last two commands (add eth0 first), then both will succeed. If after that, you remove eth0 and try to re-add it, it will fail!

Quoted 8 lines

It appears to be enough to simply check adj_list to keeps things safe.

I've tried stacking multiple devices multiple times in all different combinations, and either rx_handler registration prevented the stacking of the device linking cought the error.

Good catch.

Quoted 20 lines

---
net/core/dev.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
index c7ba038..2c1c67f 100644
@@ -5209,7 +5209,7 @@ static int __netdev_upper_dev_link(struct net_device *dev,
 	if (__netdev_find_adj(upper_dev, dev, &upper_dev->all_adj_list.upper))
 		return -EBUSY;
 
-	if (__netdev_find_adj(dev, upper_dev, &dev->all_adj_list.upper))
+	if (__netdev_find_adj(dev, upper_dev, &dev->adj_list.upper))
 		return -EEXIST;
 
 	if (master && netdev_master_upper_dev_get(dev))
Signature · 1 line
1.9.3
maintainer Applied
#3 lore raw
In reply to Vladislav Yasevich

From: Vladislav Yasevich <[email protected]>
Date: Sat, 2 May 2015 21:33:44 -0400

Quoted 17 lines

The code in __netdev_upper_dev_link() has an over-stringent loop detection logic that actually prevents valid configurations from working correctly.

In particular, the logic returns an error if an upper device is already in the list of all upper devices for a given dev. This particular check seems to be a overzealous as it disallows perfectly valid configurations. For example:

  # ip l a link eth0 name eth0.10 type vlan id 10
  # ip l a dev br0 typ bridge
  # ip l s eth0.10 master br0
  # ip l s eth0 master br0  <--- Will fail

If you switch the last two commands (add eth0 first), then both will succeed. If after that, you remove eth0 and try to re-add it, it will fail!

Quoted 8 lines

It appears to be enough to simply check adj_list to keeps things safe.

I've tried stacking multiple devices multiple times in all different combinations, and either rx_handler registration prevented the stacking of the device linking cought the error.

Applied, thanks Vlad.

#4 lore raw
Quoted 23 lines · David Miller

From: Vladislav Yasevich <[email protected]>
Date: Sat, 2 May 2015 21:33:44 -0400

Quoted 20 lines

The code in __netdev_upper_dev_link() has an over-stringent loop detection logic that actually prevents valid configurations from working correctly.

In particular, the logic returns an error if an upper device is already in the list of all upper devices for a given dev. This particular check seems to be a overzealous as it disallows perfectly valid configurations. For example:

  # ip l a link eth0 name eth0.10 type vlan id 10
  # ip l a dev br0 typ bridge
  # ip l s eth0.10 master br0
  # ip l s eth0 master br0  <--- Will fail

If you switch the last two commands (add eth0 first), then both will succeed. If after that, you remove eth0 and try to re-add it, it will fail!

It appears to be enough to simply check adj_list to keeps things safe.

Quoted 8 lines
Quoted 5 lines

I've tried stacking multiple devices multiple times in all different combinations, and either rx_handler registration prevented the stacking of the device linking cought the error.

Applied, thanks Vlad.

Hi Dave

Can you also queue it for stable. This has been broken for a while. Thanks
-vlad

maintainer
#5 lore raw

From: Vlad Yasevich <[email protected]>
Date: Mon, 04 May 2015 15:55:48 -0400

Quoted 1 line

Can you also queue it for stable. This has been broken for a while.

Done.