]> git.baikalelectronics.ru Git - kernel.git/commit
net: dsa: Fix stale cpu_switch reference after unbind then bind
authorFlorian Fainelli <f.fainelli@gmail.com>
Sat, 3 Jun 2017 05:05:23 +0000 (22:05 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 5 Jun 2017 02:55:17 +0000 (22:55 -0400)
commite3a3bafa51fa577e1c90df28be96acbf28e36cc6
tree8d489cb54759623d4118296d575c6d9a13266162
parenta2ad1a72264afba630e58cd1f564dae7b963f27e
net: dsa: Fix stale cpu_switch reference after unbind then bind

Commit e38e48c43dde ("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: e38e48c43dde ("net: dsa: use cpu_switch instead of ds[0]")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa2.c