* [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove()
@ 2019-11-03 3:13 Florian Fainelli
2019-11-03 3:53 ` Vivien Didelot
2019-11-06 1:55 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Florian Fainelli @ 2019-11-03 3:13 UTC (permalink / raw)
To: netdev
Cc: rmk+kernel, hkallweit1, Florian Fainelli, Andrew Lunn,
Vivien Didelot, David S. Miller, open list
The order in which the ports are deleted from the list and freed and the
call to dsa_tree_remove_switch() 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>
---
net/dsa/dsa2.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove()
2019-11-03 3:13 [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove() Florian Fainelli
@ 2019-11-03 3:53 ` Vivien Didelot
2019-11-06 1:55 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Vivien Didelot @ 2019-11-03 3:53 UTC (permalink / raw)
To: Florian Fainelli
Cc: netdev, rmk+kernel, hkallweit1, Florian Fainelli, Andrew Lunn,
David S. Miller, open list
On Sat, 2 Nov 2019 20:13:26 -0700, Florian Fainelli <f.fainelli@gmail.com> wrote:
> The order in which the ports are deleted from the list and freed and the
> call to dsa_tree_remove_switch() is done is reversed, which leads to an
s/dsa_tree_remove_switch/dsa_switch_remove/
> 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>
Thanks for reporting and fixing this!
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove()
2019-11-03 3:13 [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove() Florian Fainelli
2019-11-03 3:53 ` Vivien Didelot
@ 2019-11-06 1:55 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-11-06 1:55 UTC (permalink / raw)
To: f.fainelli
Cc: netdev, rmk+kernel, hkallweit1, andrew, vivien.didelot, linux-kernel
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Sat, 2 Nov 2019 20:13:26 -0700
> The order in which the ports are deleted from the list and freed and the
> call to dsa_tree_remove_switch() 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>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-06 1:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-03 3:13 [PATCH net-next] net: dsa: Fix use after free in dsa_switch_remove() Florian Fainelli
2019-11-03 3:53 ` Vivien Didelot
2019-11-06 1:55 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).