drivers/net: fixing a datarace related to update_stats()
PATCH 1/1 drivers/net: fixing a datarace related to update_stats()
Fixing a datarace.
As indicated by the following comment, a lock must be held before calling function update_stats(). This rule is followed in some cases, but not in others. For example, the lock is held when the function is called in function el3_get_stats(), but the lock is NOT held when called in el3_close(). It can cause potential data races.
/*
...
Caller must hold the lock for this
*/
static void update_stats(struct net_device *dev)
{
...
}
---
drivers/net/pcmcia/3c589_cs.c +3 -0
@@ -920,6 +920,7 @@ static int el3_close(struct net_device *struct el3_private *lp =netdev_priv (dev);struct pcmcia_device *link = lp->p_dev;unsigned int ioaddr = dev->base_addr; +unsigned long flags;DEBUG (1 ,"%s: shutting down ethercard.\n" , dev->name);
@@ -947,7 +948,9 @@ static int el3_close(struct net_device */* Check if the card still exists */ if ((inw (ioaddr+EL3_STATUS ) &0xe000 ) ==0x2000 ) +spin_lock_irqsave (&lp->lock, flags);update_stats (dev); +spin_unlock_irqrestore (&lp->lock, flags); } link->open--;
(Please Cc: [email protected])
Lin Tan <[email protected]> :
[drivers/net/pcmcia/3c589_cs.c race]
Quoted 5 lines
As indicated by the following comment, a lock must be held before calling function
update_stats(). This rule is followed in some cases, but not in others. For example, the lock is held when the function is called in functionel3_get_stats(), but the lock is NOT held when called inel3_close(). It can cause potential data races.
I would not bet that the irq handler does not race with el3_close() in the first place. Could you dig it ?
Signature · 1 line
Ueimor