team: couple of fixes
Subsystems (3)
Jiri Pirko
maintainercover 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
Jiri Pirko
maintainerPATCH 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
@@ -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
@@ -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
Jiri Pirko
maintainerPATCH 2/3 team: move add to port list before port enablement
In reply to Jiri Pirkoteam_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
@@ -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
Jiri Pirko
maintainerPATCH 3/3 team: fix checks in team_get_first_port_txable_rcu()
In reply to Jiri Pirkoshould 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
@@ -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
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Sat, 8 Jun 2013 15:00:52 +0200
Quoted 4 lines
Jiri Pirko (3):
team: check return value ofteam_get_port_by_index_rcu()for NULL
team: move add to port list before port enablement
team: fix checks inteam_get_first_port_txable_rcu()
Series applied, thanks Jiri.
Jiri Pirko
maintainerQuoted 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 +0200Quoted 4 lines
Jiri Pirko (3):
team: check return value ofteam_get_port_by_index_rcu()for NULL
team: move add to port list before port enablement
team: fix checks inteam_get_first_port_txable_rcu()Series applied, thanks Jiri.
Thanks Dave. Please note that this is suitable for stable trees as well.
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 ofteam_get_port_by_index_rcu()for NULL
team: move add to port list before port enablement
team: fix checks inteam_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.