diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2019-11-03 06:13:26 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-11-06 04:53:58 +0300 |
commit | c058f6dfeb1c645e77dc89d1690848ca06f45735 (patch) | |
tree | a3da3bf333e70412ca42f2bcc1fb58318cc8e2af /net/dsa/dsa2.c | |
parent | 2bceefbe557f4b4e875ca6db19a9f8a8bb3d557d (diff) | |
download | linux-c058f6dfeb1c645e77dc89d1690848ca06f45735.tar.xz |
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: 05f294a85235 ("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>
Diffstat (limited to 'net/dsa/dsa2.c')
-rw-r--r-- | net/dsa/dsa2.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index ff2fa3950c62..9ef2caa13f27 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -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); } |