Skip to contentSkip to conversation

team: fix possible recursive locking when add slaves

PATCH Superseded Hangbin Liu 3 participants 5 messages Apr 17, 2019 – Apr 19, 2019

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

PATCH 1/1 team: fix possible recursive locking when add slaves

If we add a bond device which is already the master of the team interface, we will hold the team->lock in team_add_slave() first and then request the lock in team_set_mac_address() again. The functions are called like:

- team_add_slave()
- team_port_add()
- team_port_enter()
- team_modeop_port_enter()
- __set_port_dev_addr()
- dev_set_mac_address()
- bond_set_mac_address()
- dev_set_mac_address()
- team_set_mac_address

Although team_upper_dev_link() would check the upper devices but it is called too late. Fix it by adding a checking before processing the slave.

Fixes 3d249d4ca7d0 ("net: introduce ethernet teaming device")
---
 drivers/net/team/team.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/team/team.c +7 -0
index 9ce61b019aad..8313c4f2b635 100644
@@ -1156,6 +1156,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
 		return -EINVAL;
 	}
 
+	if (netdev_has_upper_dev(dev, port_dev)) {
+		NL_SET_ERR_MSG(extack, "Device is already an upper device of the team interface");
+		netdev_err(dev, "Device %s is already an upper device "
+				"of the team interface\n", portname);
+		return -EBUSY;
+	}
+
 	if (port_dev->features & NETIF_F_VLAN_CHALLENGED &&
 	    vlan_uses_dev(dev)) {
 		NL_SET_ERR_MSG(extack, "Device is VLAN challenged and team device has VLAN set up");
Signature · 1 line
2.19.2
maintainer
#1 lore raw

From: Hangbin Liu <[email protected]>
Date: Wed, 17 Apr 2019 20:12:11 +0800

Quoted 14 lines

If we add a bond device which is already the master of the team interface, we will hold the team->lock in team_add_slave() first and then request the lock in team_set_mac_address() again. The functions are called like:

- team_add_slave()
- team_port_add()
- team_port_enter()
- team_modeop_port_enter()
- __set_port_dev_addr()
- dev_set_mac_address()
- bond_set_mac_address()
- dev_set_mac_address()
- team_set_mac_address

Quoted 5 lines

Although team_upper_dev_link() would check the upper devices but it is called too late. Fix it by adding a checking before processing the slave.

Fixes 3d249d4ca7d0 ("net: introduce ethernet teaming device")

Jiri, please review.

Thank you.

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Hangbin Liu
Quoted 28 lines · Wed, Apr 17, 2019 at 02:12:11PM CEST, [email protected] wrote:

If we add a bond device which is already the master of the team interface, we will hold the team->lock in team_add_slave() first and then request the lock in team_set_mac_address() again. The functions are called like:

- team_add_slave()
- team_port_add()
- team_port_enter()
- team_modeop_port_enter()
- __set_port_dev_addr()
- dev_set_mac_address()
- bond_set_mac_address()
- dev_set_mac_address()
- team_set_mac_address

Although team_upper_dev_link() would check the upper devices but it is called too late. Fix it by adding a checking before processing the slave.

Fixes 3d249d4ca7d0 ("net: introduce ethernet teaming device")

---
drivers/net/team/team.c | 7 +++++++

1 file changed, 7 insertions(+)
drivers/net/team/team.c +0 -0
index 9ce61b019aad..8313c4f2b635 100644

drivers/net/team/team.c static int team_port_add(struct team *team, struct net_device *port_dev, · line 1162

Quoted 7 lines
drivers/net/team/team.c +4 -0
@@ -1156,6 +1156,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
 		return -EINVAL;
 	}
 
+	if (netdev_has_upper_dev(dev, port_dev)) {
+		NL_SET_ERR_MSG(extack, "Device is already an upper device of the team interface");
+		netdev_err(dev, "Device %s is already an upper device "
+				"of the team interface\n", portname);

No wraps in strings please.
Otherwise, this looks fine. Feel free to add my ack:

Quoted 9 lines
drivers/net/team/team.c +3 -0
+		return -EBUSY;
+	}
+
 	if (port_dev->features & NETIF_F_VLAN_CHALLENGED &&
 	    vlan_uses_dev(dev)) {
 		NL_SET_ERR_MSG(extack, "Device is VLAN challenged and team device has VLAN set up");
Signature · 1 line
2.19.2
#3 lore raw

PATCH v2 1/1 team: fix possible recursive locking when add slaves

In reply to Hangbin Liu

If we add a bond device which is already the master of the team interface, we will hold the team->lock in team_add_slave() first and then request the lock in team_set_mac_address() again. The functions are called like:

- team_add_slave()
- team_port_add()
- team_port_enter()
- team_modeop_port_enter()
- __set_port_dev_addr()
- dev_set_mac_address()
- bond_set_mac_address()
- dev_set_mac_address()
- team_set_mac_address

Although team_upper_dev_link() would check the upper devices but it is called too late. Fix it by adding a checking before processing the slave.

v2: Do not split the string in netdev_err()

Fixes 3d249d4ca7d0 ("net: introduce ethernet teaming device")
---
 drivers/net/team/team.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/team/team.c +7 -0
index 9ce61b019aad..16963f7a88f7 100644
@@ -1156,6 +1156,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
 		return -EINVAL;
 	}
 
+	if (netdev_has_upper_dev(dev, port_dev)) {
+		NL_SET_ERR_MSG(extack, "Device is already an upper device of the team interface");
+		netdev_err(dev, "Device %s is already an upper device of the team interface\n",
+			   portname);
+		return -EBUSY;
+	}
+
 	if (port_dev->features & NETIF_F_VLAN_CHALLENGED &&
 	    vlan_uses_dev(dev)) {
 		NL_SET_ERR_MSG(extack, "Device is VLAN challenged and team device has VLAN set up");
Signature · 1 line
2.19.2
maintainer
#4 lore raw

From: Hangbin Liu <[email protected]>
Date: Fri, 19 Apr 2019 14:31:00 +0800

Quoted 14 lines

If we add a bond device which is already the master of the team interface, we will hold the team->lock in team_add_slave() first and then request the lock in team_set_mac_address() again. The functions are called like:

- team_add_slave()
- team_port_add()
- team_port_enter()
- team_modeop_port_enter()
- __set_port_dev_addr()
- dev_set_mac_address()
- bond_set_mac_address()
- dev_set_mac_address()
- team_set_mac_address

Quoted 8 lines

Although team_upper_dev_link() would check the upper devices but it is called too late. Fix it by adding a checking before processing the slave.

v2: Do not split the string in netdev_err()

Fixes 3d249d4ca7d0 ("net: introduce ethernet teaming device")

Applied and queued up for -stable, thanks.