Skip to content

Commit b07ac98

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Fix stale cpu_switch reference after unbind then bind
Commit 9520ed8 ("net: dsa: use cpu_switch instead of ds[0]") replaced the use of dst->ds[0] with dst->cpu_switch since that is functionally equivalent, however, we can now run into an use after free scenario after unbinding then rebinding the switch driver. The use after free happens because we do correctly initialize dst->cpu_switch the first time we probe in dsa_cpu_parse(), then we unbind the driver: dsa_dst_unapply() is called, and we rebind again. dst->cpu_switch now points to a freed "ds" structure, and so when we finally dereference it in dsa_cpu_port_ethtool_setup(), we oops. To fix this, simply set dst->cpu_switch to NULL in dsa_dst_unapply() which guarantees that we always correctly re-assign dst->cpu_switch in dsa_cpu_parse(). Fixes: 9520ed8 ("net: dsa: use cpu_switch instead of ds[0]") Signed-off-by: Florian Fainelli <[email protected]> Reviewed-by: Vivien Didelot <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e3e86b5 commit b07ac98

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/dsa/dsa2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,10 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst)
484484
dsa_ds_unapply(dst, ds);
485485
}
486486

487-
if (dst->cpu_switch)
487+
if (dst->cpu_switch) {
488488
dsa_cpu_port_ethtool_restore(dst->cpu_switch);
489+
dst->cpu_switch = NULL;
490+
}
489491

490492
pr_info("DSA: tree %d unapplied\n", dst->tree);
491493
dst->applied = false;

0 commit comments

Comments
 (0)