Skip to content

Commit

Permalink
net: dsa: Fix use after free in dsa_switch_remove()
Browse files Browse the repository at this point in the history
The order in which the ports are deleted from the list and freed and the
call to dsa_switch_remove() is done is reversed, which leads to an
use after free condition. Reverse the two: first tear down the ports and
switch from the fabric, then free the ports associated with that switch
fabric.

Fixes: 05f294a ("net: dsa: allocate ports on touch")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Florian Fainelli authored and David S. Miller committed Nov 6, 2019
1 parent 2bceefb commit c058f6d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,12 +874,13 @@ static void dsa_switch_remove(struct dsa_switch *ds)
struct dsa_switch_tree *dst = ds->dst;
struct dsa_port *dp, *next;

dsa_tree_teardown(dst);

list_for_each_entry_safe(dp, next, &dst->ports, list) {
list_del(&dp->list);
kfree(dp);
}

dsa_tree_teardown(dst);
dsa_tree_put(dst);
}

Expand Down

0 comments on commit c058f6d

Please sign in to comment.