net: dsa: Fix use after free in dsa_switch_remove()
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: 05f294a852 ("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>
This commit is contained in:
committed by
David S. Miller
parent
2bceefbe55
commit
c058f6dfeb
@@ -874,12 +874,13 @@ static void dsa_switch_remove(struct dsa_switch *ds)
|
|||||||
struct dsa_switch_tree *dst = ds->dst;
|
struct dsa_switch_tree *dst = ds->dst;
|
||||||
struct dsa_port *dp, *next;
|
struct dsa_port *dp, *next;
|
||||||
|
|
||||||
|
dsa_tree_teardown(dst);
|
||||||
|
|
||||||
list_for_each_entry_safe(dp, next, &dst->ports, list) {
|
list_for_each_entry_safe(dp, next, &dst->ports, list) {
|
||||||
list_del(&dp->list);
|
list_del(&dp->list);
|
||||||
kfree(dp);
|
kfree(dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
dsa_tree_teardown(dst);
|
|
||||||
dsa_tree_put(dst);
|
dsa_tree_put(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user