* [PATCH net] team: fix possible recursive locking when add slaves
@ 2019-04-17 12:12 Hangbin Liu
2019-04-18 23:39 ` David Miller
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Hangbin Liu @ 2019-04-17 12:12 UTC (permalink / raw)
To: netdev; +Cc: Jiri Pirko, davem, Xin Long, 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.
Fixes: 3d249d4ca7d0 ("net: introduce ethernet teaming device")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
drivers/net/team/team.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 9ce61b019aad..8313c4f2b635 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -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");
--
2.19.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] team: fix possible recursive locking when add slaves
2019-04-17 12:12 [PATCH net] team: fix possible recursive locking when add slaves Hangbin Liu
@ 2019-04-18 23:39 ` David Miller
2019-04-19 5:55 ` Jiri Pirko
2019-04-19 6:31 ` [PATCHv2 " Hangbin Liu
2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-04-18 23:39 UTC (permalink / raw)
To: liuhangbin; +Cc: netdev, jiri, lucien.xin
From: Hangbin Liu <liuhangbin@gmail.com>
Date: Wed, 17 Apr 2019 20:12:11 +0800
> 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")
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Jiri, please review.
Thank you.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] team: fix possible recursive locking when add slaves
2019-04-17 12:12 [PATCH net] team: fix possible recursive locking when add slaves Hangbin Liu
2019-04-18 23:39 ` David Miller
@ 2019-04-19 5:55 ` Jiri Pirko
2019-04-19 6:31 ` [PATCHv2 " Hangbin Liu
2 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2019-04-19 5:55 UTC (permalink / raw)
To: Hangbin Liu; +Cc: netdev, davem, Xin Long
Wed, Apr 17, 2019 at 02:12:11PM CEST, liuhangbin@gmail.com 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")
>Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>---
> drivers/net/team/team.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
>diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
>index 9ce61b019aad..8313c4f2b635 100644
>--- a/drivers/net/team/team.c
>+++ b/drivers/net/team/team.c
>@@ -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:
Acked-by: Jiri Pirko <jiri@mellanox.com>
>+ 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");
>--
>2.19.2
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCHv2 net] team: fix possible recursive locking when add slaves
2019-04-17 12:12 [PATCH net] team: fix possible recursive locking when add slaves Hangbin Liu
2019-04-18 23:39 ` David Miller
2019-04-19 5:55 ` Jiri Pirko
@ 2019-04-19 6:31 ` Hangbin Liu
2019-04-19 21:58 ` David Miller
2 siblings, 1 reply; 5+ messages in thread
From: Hangbin Liu @ 2019-04-19 6:31 UTC (permalink / raw)
To: netdev; +Cc: Jiri Pirko, Xin Long, davem, 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")
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
drivers/net/team/team.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
index 9ce61b019aad..16963f7a88f7 100644
--- a/drivers/net/team/team.c
+++ b/drivers/net/team/team.c
@@ -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");
--
2.19.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCHv2 net] team: fix possible recursive locking when add slaves
2019-04-19 6:31 ` [PATCHv2 " Hangbin Liu
@ 2019-04-19 21:58 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-04-19 21:58 UTC (permalink / raw)
To: liuhangbin; +Cc: netdev, jiri, lucien.xin
From: Hangbin Liu <liuhangbin@gmail.com>
Date: Fri, 19 Apr 2019 14:31:00 +0800
> 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")
> Acked-by: Jiri Pirko <jiri@mellanox.com>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-04-19 21:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 12:12 [PATCH net] team: fix possible recursive locking when add slaves Hangbin Liu
2019-04-18 23:39 ` David Miller
2019-04-19 5:55 ` Jiri Pirko
2019-04-19 6:31 ` [PATCHv2 " Hangbin Liu
2019-04-19 21:58 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).