aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2009-07-02 19:03:55 -0400
committerDavid S. Miller <davem@davemloft.net>2009-07-05 21:03:18 -0400
commitd23e43658aed286b885d398ff0810f04f6aae97f (patch)
tree49449c308390dc319fc83378dbd357041c7f27ea
parentc001c213b109c8baeeb6d012b422bf059b18368f (diff)
tun: Fix device unregister race
It is currently possible for an asynchronous device unregister to cause the same tun device to be unregistered twice. This is because the unregister in tun_chr_close only checks whether __tun_get(tfile) != NULL. This however has nothing to do with whether the device has already been unregistered. All it tells you is whether __tun_detach has been called. This patch fixes this by using the most obvious thing to test whether the device has been unregistered. It also moves __tun_detach outside of rtnl_unlock since nothing that it does requires that lock. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/tun.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 11a0ba47b677..b393536012fb 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1324,20 +1324,22 @@ static int tun_chr_close(struct inode *inode, struct file *file)
1324 struct tun_file *tfile = file->private_data; 1324 struct tun_file *tfile = file->private_data;
1325 struct tun_struct *tun; 1325 struct tun_struct *tun;
1326 1326
1327
1328 rtnl_lock();
1329 tun = __tun_get(tfile); 1327 tun = __tun_get(tfile);
1330 if (tun) { 1328 if (tun) {
1331 DBG(KERN_INFO "%s: tun_chr_close\n", tun->dev->name); 1329 struct net_device *dev = tun->dev;
1330
1331 DBG(KERN_INFO "%s: tun_chr_close\n", dev->name);
1332 1332
1333 __tun_detach(tun); 1333 __tun_detach(tun);
1334 1334
1335 /* If desireable, unregister the netdevice. */ 1335 /* If desireable, unregister the netdevice. */
1336 if (!(tun->flags & TUN_PERSIST)) 1336 if (!(tun->flags & TUN_PERSIST)) {
1337 unregister_netdevice(tun->dev); 1337 rtnl_lock();
1338 1338 if (dev->reg_state == NETREG_REGISTERED)
1339 unregister_netdevice(dev);
1340 rtnl_unlock();
1341 }
1339 } 1342 }
1340 rtnl_unlock();
1341 1343
1342 tun = tfile->tun; 1344 tun = tfile->tun;
1343 if (tun) 1345 if (tun)