Re: [net v4] net: dsa: microchip: fix race condition

From: Jakub Kicinski
Date: Mon Oct 12 2020 - 13:05:06 EST


On Mon, 12 Oct 2020 10:39:42 +0200 Christian Eggers wrote:
> Between queuing the delayed work and finishing the setup of the dsa
> ports, the process may sleep in request_module() (via
> phy_device_create()) and the queued work may be executed prior to the
> switch net devices being registered. In ksz_mib_read_work(), a NULL
> dereference will happen within netof_carrier_ok(dp->slave).
>
> Not queuing the delayed work in ksz_init_mib_timer() makes things even
> worse because the work will now be queued for immediate execution
> (instead of 2000 ms) in ksz_mac_link_down() via
> dsa_port_link_register_of().

>
> Solution:
> 1. Do not queue (only initialize) delayed work in ksz_init_mib_timer().
> 2. Only queue delayed work in ksz_mac_link_down() if init is completed.
> 3. Queue work once in ksz_switch_register(), after dsa_register_switch()
> has completed.
>
> Fixes: 7c6ff470aa86 ("net: dsa: microchip: add MIB counter reading support")
> Signed-off-by: Christian Eggers <ceggers@xxxxxxx>
> Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
> Reviewed-by: Vladimir Oltean <olteanv@xxxxxxxxx>
> Reviewed-by: Jakub Kicinski <kuba@xxxxxxxxxx>

Now you went too far in the opposite direction, I never gave you my
explicit tag :) So I'll drop it.

Applied and queued for stable, thanks!