r8169: fix a race between PCI probe and dev_open
Subsystems (2)
PATCH 1/1 r8169: fix a race between PCI probe and dev_open
Call chain:
-> rtl8169_init_one
-> register_netdev (dev_open starts to race...)
-> rtl8169_init_phy
-> rtl8169_set_speed
-> tp->set_speed
-> mod_timer(&tp->timer, ...) (if netif_running() is true)As netif_running() is true just before dev->open() is issued and the timer is initialized during dev->open, mod_timer() meets an uninitialized tp->timer and oopses.
rtl8169_init_phy is only used on rtl8169_init_one so it's fine to never ask it to activate the timer: the racing dev->open will do it anyway.
--- drivers/net/r8169.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/r8169.c +1 -1
@@ -1448,7 +1448,7 @@ static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp)rtl8169_phy_reset (dev, tp); -rtl8169_set_speed (dev, autoneg, speed, duplex); + tp->set_speed (dev, autoneg, speed, duplex);if ((RTL_R8 (PHYstatus) & TBI_Enable) &&netif_msg_link (tp)) printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name);
Signature · 1 line
1.4.4.4
Quoted 11 lines · Francois Romieu
Call chain:
->rtl8169_init_one
->register_netdev(dev_openstarts to race...)
->rtl8169_init_phy-> rtl8169_set_speed -> tp->set_speed -> mod_timer(&tp->timer, ...) (if netif_running() is true)As
netif_running()is true just beforedev->open()is issued and the timer is initialized duringdev->open,mod_timer()meets an uninitializedtp->timerand oopses.
Doesn't this basically mean that *any* use of "rtl8169_set_speed()" is buggy?
Anyway, I'm going to wait for somebody smarter than me to ACK this patch. Jeff?
Linus
Quoted 3 lines · Francois Romieu
rtl8169_init_phyis only used onrtl8169_init_oneso it's fine to never ask it to activate the timer: the racingdev->openwill do it anyway.
Does rtl8169_init_phy need to occur after register_netdev? Normally register_netdev should be the very last thing in a probe routine.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtLinus Torvalds <[email protected]> :
[...]
Quoted 2 lines
Doesn't this basically mean that *any* use of "
rtl8169_set_speed()" is buggy?
The second use of rtl8169_set_speed is in the change_mtu handler which performs a complete down/cycle after a release of the timer. It's still ugly though. If the current buggy behavior can be lived with, I'll happily postpone the needed deeper changes.
Signature · 1 line
Ueimor
Herbert Xu <[email protected]> :
[...]
Quoted 1 line
Normally
register_netdevshould be the very last thing in a probe routine.
Yes. I did not feel safe changing it before 2.6.20.
Signature · 1 line
Ueimor
Quoted 11 lines · Linus Torvalds
Quoted 8 lines · Francois Romieu
Call chain:
->rtl8169_init_one
->register_netdev(dev_openstarts to race...)
->rtl8169_init_phy-> rtl8169_set_speed -> tp->set_speed -> mod_timer(&tp->timer, ...) (if netif_running() is true)
Quoted 5 lines
Quoted 3 lines
As
netif_running()is true just beforedev->open()is issued and the timer is initialized duringdev->open,mod_timer()meets an uninitializedtp->timerand oopses.Doesn't this basically mean that *any* use of "
rtl8169_set_speed()" is buggy?
No, just the first use, after which the one-time initialization occurs.
Quoted 1 line
Anyway, I'm going to wait for somebody smarter than me to ACK this patch. Jeff?
I would rather have something more like the attached patch, which initializes the timer with the rest of the private-struct initialization. Just like most other net drivers do.
Quoted 2 lines · And Herbert Xu
Does
rtl8169_init_phyneed to occur afterregister_netdev? Normallyregister_netdevshould be the very last thing in a probe routine.
Quite correct.
So... anybody wanna test my patch (didn't compile it, but it looks right) and confirm that it fixes things?
Jeff
drivers/net/r8169.c +5 -5
@@ -1369,11 +1369,7 @@ static inline void rtl8169_request_timer(struct net_device *dev) (tp->phy_version >= RTL_GIGA_PHY_VER_H))return ; -init_timer (timer); - timer->expires = jiffies +RTL8169_PHY_TIMEOUT ; - timer->data = (unsigned long )(dev); - timer->function = rtl8169_phy_timer; -add_timer (timer); +mod_timer (timer, jiffies +RTL8169_PHY_TIMEOUT ); }#ifdef CONFIG_NET_POLL_CONTROLLER
@@ -1686,6 +1682,10 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->mmio_addr = ioaddr; tp->align = rtl_cfg_info[ent->driver_data].align; +init_timer (&tp->timer); + tp->timer.data = (unsigned long )(dev); + tp->timer.function = rtl8169_phy_timer; +spin_lock_init (&tp->lock); rc =register_netdev (dev);