mirror of https://gitee.com/openkylin/linux.git
8098bd69bc
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().
Call tree:
ksz9477_i2c_probe()
\--ksz9477_switch_register()
\--ksz_switch_register()
+--dsa_register_switch()
| \--dsa_switch_probe()
| \--dsa_tree_setup()
| \--dsa_tree_setup_switches()
| +--dsa_switch_setup()
| | +--ksz9477_setup()
| | | \--ksz_init_mib_timer()
| | | |--/* Start the timer 2 seconds later. */
| | | \--schedule_delayed_work(&dev->mib_read, msecs_to_jiffies(2000));
| | \--__mdiobus_register()
| | \--mdiobus_scan()
| | \--get_phy_device()
| | +--get_phy_id()
| | \--phy_device_create()
| | |--/* sleeping, ksz_mib_read_work() can be called meanwhile */
| | \--request_module()
| |
| \--dsa_port_setup()
| +--/* Called for non-CPU ports */
| +--dsa_slave_create()
| | +--/* Too late, ksz_mib_read_work() may be called beforehand */
| | \--port->slave = ...
| ...
| +--Called for CPU port */
| \--dsa_port_link_register_of()
| \--ksz_mac_link_down()
| +--/* mib_read must be initialized here */
| +--/* work is already scheduled, so it will be executed after 2000 ms */
| \--schedule_delayed_work(&dev->mib_read, 0);
\-- /* here port->slave is setup properly, scheduling the delayed work should be safe */
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:
|
||
---|---|---|
.. | ||
b53 | ||
microchip | ||
mv88e6xxx | ||
ocelot | ||
qca | ||
sja1105 | ||
Kconfig | ||
Makefile | ||
bcm_sf2.c | ||
bcm_sf2.h | ||
bcm_sf2_cfp.c | ||
bcm_sf2_regs.h | ||
dsa_loop.c | ||
dsa_loop.h | ||
dsa_loop_bdinfo.c | ||
lan9303-core.c | ||
lan9303.h | ||
lan9303_i2c.c | ||
lan9303_mdio.c | ||
lantiq_gswip.c | ||
lantiq_pce.h | ||
mt7530.c | ||
mt7530.h | ||
mv88e6060.c | ||
mv88e6060.h | ||
qca8k.c | ||
qca8k.h | ||
realtek-smi-core.c | ||
realtek-smi-core.h | ||
rtl8366.c | ||
rtl8366rb.c | ||
vitesse-vsc73xx-core.c | ||
vitesse-vsc73xx-platform.c | ||
vitesse-vsc73xx-spi.c | ||
vitesse-vsc73xx.h |