netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
	dwmw2@infradead.org, netdev@vger.kernel.org,
	johannes@sipsolutions.net
Subject: Re: tun netns BUG()
Date: Fri, 03 Jul 2009 07:52:30 -0700	[thread overview]
Message-ID: <m163e9hl8x.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <20090703090355.GA25768@gondor.apana.org.au> (Herbert Xu's message of "Fri\, 3 Jul 2009 17\:03\:55 +0800")

Herbert Xu <herbert@gondor.apana.org.au> writes:

> On Fri, Jul 03, 2009 at 04:35:01PM +0800, Herbert Xu wrote:
>> 
>> This just turns a wide-open race into a less likely one (that's
>> why it appears to fix the problem).  The crux of the issue is that 
>> __tun_get(tfile) != NULL has nothing to do with whether the device
>> has been unregistered.

Not so.

unregister_netdevice
  rollback_registered
    tun_net_unit
      __tun_detach.


Further we need rtnl_lock around __tun_detach.

Eric



> 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>
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 11a0ba4..b393536 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)
>  	struct tun_file *tfile = file->private_data;
>  	struct tun_struct *tun;
>  
> -
> -	rtnl_lock();
>  	tun = __tun_get(tfile);
>  	if (tun) {
> -		DBG(KERN_INFO "%s: tun_chr_close\n", tun->dev->name);
> +		struct net_device *dev = tun->dev;
> +
> +		DBG(KERN_INFO "%s: tun_chr_close\n", dev->name);
>  
>  		__tun_detach(tun);
>  
>  		/* If desireable, unregister the netdevice. */
> -		if (!(tun->flags & TUN_PERSIST))
> -			unregister_netdevice(tun->dev);
> -
> +		if (!(tun->flags & TUN_PERSIST)) {
> +			rtnl_lock();
> +			if (dev->reg_state == NETREG_REGISTERED)
> +				unregister_netdevice(dev);
> +			rtnl_unlock();
> +		}
>  	}
> -	rtnl_unlock();
>  
>  	tun = tfile->tun;
>  	if (tun)
>
> Cheers,
> -- 
> Visit Openswan at http://www.openswan.org/
> Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-07-03 14:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 19:05 tun netns BUG() David Woodhouse
2009-06-05  1:19 ` Eric W. Biederman
2009-06-05  8:42   ` David Woodhouse
2009-06-05  9:17     ` David Woodhouse
2009-06-05 23:24       ` Eric W. Biederman
2009-06-06  7:06         ` David Woodhouse
2009-06-08  7:44           ` David Miller
2009-07-03  8:35         ` Herbert Xu
2009-07-03  9:03           ` Herbert Xu
2009-07-03 14:52             ` Eric W. Biederman [this message]
2009-07-03 15:25               ` Herbert Xu
2009-07-06  2:01                 ` David Miller
2009-06-05 23:20     ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m163e9hl8x.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=davem@davemloft.net \
    --cc=dwmw2@infradead.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=johannes@sipsolutions.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).