Skip to contentSkip to conversation

team: couple of fixes

PATCH Applied Jiri Pirko 2 participants 7 messages Jun 8, 2013 – Jun 12, 2013

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

cover team: couple of fixes

Jiri Pirko (3):
team: check return value of team_get_port_by_index_rcu() for NULL
team: move add to port list before port enablement
team: fix checks in team_get_first_port_txable_rcu()

 drivers/net/team/team.c                 | 2 +-
 drivers/net/team/team_mode_random.c     | 2 ++
 drivers/net/team/team_mode_roundrobin.c | 2 ++
 include/linux/if_team.h                 | 4 ++--
 4 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 1/3 team: check return value of team_get_port_by_index_rcu() for NULL

team_get_port_by_index_rcu() might return NULL due to race between port removal and skb tx path. Panic is easily triggeable when txing packets and adding/removing port in a loop.

introduced by commit 3d249d4ca "net: introduce ethernet teaming device" and commit 753f993911b "team: introduce random mode" (for random mode)

---
 drivers/net/team/team_mode_random.c     | 2 ++
 drivers/net/team/team_mode_roundrobin.c | 2 ++
 2 files changed, 4 insertions(+)
drivers/net/team/team_mode_random.c +2 -0
index 5ca14d4..7f032e2 100644
@@ -28,6 +28,8 @@ static bool rnd_transmit(struct team *team, struct sk_buff *skb)
 
 	port_index = random_N(team->en_port_count);
 	port = team_get_port_by_index_rcu(team, port_index);
+	if (unlikely(!port))
+		goto drop;
 	port = team_get_first_port_txable_rcu(team, port);
 	if (unlikely(!port))
 		goto drop;
drivers/net/team/team_mode_roundrobin.c +2 -0
index d268e4d..472623f 100644
@@ -32,6 +32,8 @@ static bool rr_transmit(struct team *team, struct sk_buff *skb)
 
 	port_index = rr_priv(team)->sent_packets++ % team->en_port_count;
 	port = team_get_port_by_index_rcu(team, port_index);
+	if (unlikely(!port))
+		goto drop;
 	port = team_get_first_port_txable_rcu(team, port);
 	if (unlikely(!port))
 		goto drop;
Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

PATCH 2/3 team: move add to port list before port enablement

In reply to Jiri Pirko

team_port_enable() adds port to port_hashlist. Reader sees port in team_get_port_by_index_rcu() and returns it, but team_get_first_port_txable_rcu() tries to go through port_list, where the port is not inserted yet -> NULL pointer dereference.
Fix this by reordering port_list and port_hashlist insertion. Panic is easily triggeable when txing packets and adding/removing port in a loop.

Introduced by commit 3d249d4c "net: introduce ethernet teaming device"

---
 drivers/net/team/team.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/team/team.c +1 -1
index d016a76..b305105 100644
@@ -1092,8 +1092,8 @@ static int team_port_add(struct team *team, struct net_device *port_dev)
 	}
 
 	port->index = -1;
-	team_port_enable(team, port);
 	list_add_tail_rcu(&port->list, &team->port_list);
+	team_port_enable(team, port);
 	__team_compute_features(team);
 	__team_port_change_port_added(port, !!netif_carrier_ok(port_dev));
 	__team_options_change_check(team);
Signature · 1 line
1.7.11.7
author maintainer
#3 lore raw

PATCH 3/3 team: fix checks in team_get_first_port_txable_rcu()

In reply to Jiri Pirko

should be checked if "cur" is txable, not "port".

Introduced by commit 6e88e1357c "team: use function team_port_txable() for determing enabled and up port"

---
 include/linux/if_team.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/if_team.h +2 -2
index 4474557..16fae64 100644
@@ -249,12 +249,12 @@ team_get_first_port_txable_rcu(struct team *team, struct team_port *port)
 		return port;
 	cur = port;
 	list_for_each_entry_continue_rcu(cur, &team->port_list, list)
-		if (team_port_txable(port))
+		if (team_port_txable(cur))
 			return cur;
 	list_for_each_entry_rcu(cur, &team->port_list, list) {
 		if (cur == port)
 			break;
-		if (team_port_txable(port))
+		if (team_port_txable(cur))
 			return cur;
 	}
 	return NULL;
Signature · 1 line
1.7.11.7
maintainer
#4 lore raw
In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>
Date: Sat, 8 Jun 2013 15:00:52 +0200

Quoted 4 lines

Jiri Pirko (3):
team: check return value of team_get_port_by_index_rcu() for NULL
team: move add to port list before port enablement
team: fix checks in team_get_first_port_txable_rcu()

Series applied, thanks Jiri.

author maintainer
#5 lore raw
Quoted 9 lines · Wed, Jun 12, 2013 at 09:57:24AM CEST, [email protected] wrote:

From: Jiri Pirko <[email protected]>
Date: Sat, 8 Jun 2013 15:00:52 +0200

Quoted 4 lines

Jiri Pirko (3):
team: check return value of team_get_port_by_index_rcu() for NULL
team: move add to port list before port enablement
team: fix checks in team_get_first_port_txable_rcu()

Series applied, thanks Jiri.

Thanks Dave. Please note that this is suitable for stable trees as well.

maintainer Applied
#6 lore raw

From: Jiri Pirko <[email protected]>
Date: Wed, 12 Jun 2013 10:58:40 +0200

Quoted 4 lines
Quoted 3 lines · Wed, Jun 12, 2013 at 09:57:24AM CEST, [email protected] wrote:

From: Jiri Pirko <[email protected]>
Date: Sat, 8 Jun 2013 15:00:52 +0200

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Jiri Pirko (3):
team: check return value of team_get_port_by_index_rcu() for NULL
team: move add to port list before port enablement
team: fix checks in team_get_first_port_txable_rcu()

Series applied, thanks Jiri.

Thanks Dave. Please note that this is suitable for stable trees as well.

Queued up, thanks for letting me know.