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: Paul Moore <paul.moore@hp.com>,
	netdev@vger.kernel.org, David Miller <davem@davemloft.net>
Subject: Re: [RFC PATCH v1] tun: Cleanup error handling in tun_set_iff()
Date: Thu, 06 Aug 2009 07:27:13 -0700	[thread overview]
Message-ID: <m1ljlxj9vi.fsf@fess.ebiederm.org> (raw)
In-Reply-To: <20090806133746.GA28557@gondor.apana.org.au> (Herbert Xu's message of "Thu\, 6 Aug 2009 23\:37\:46 +1000")

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

> On Thu, Aug 06, 2009 at 03:21:41AM -0700, Eric W. Biederman wrote:
>>
>> Two threads one file descriptor.  Both simultaneously attempt to 
>> attach to a tun device.  One will fail, the other succeed.
>> 
>> At least that is how I read the locking.
>
> Yes but the "race" fixed by this patch is centred on the tun_attach
> call for a newly created network device.  As tun_set_iff occurs
> under RTNL, the second thread cannot start attaching until the
> creation thread has completed.  IOW the thread that creates the
> net device should always succeed in attaching.

>
> If two threads try to attach to the same device that was already
> created then yes one will fail and the other succeed.  However,
> AFAICS that case has nothing to do with this patch.

Summarizing:

tun = __tun_get(tfile);
if (!tun) { // No tun we are not attached.
	 < -------------------- race opportunity
	rtnl_lock();
        tun_set_iff();
        rtnl_unlock();
}
...

We don't test if we are attached under the rtnl
until we get to tun_attach();

So two threads can both do:

tun = __tun_get(tfile);
if (!tun) {
	rtnl_lock();
        tun_set_iff();
            dev = __dev_get_by_name(net, "not_an_interface_name");
            if (!dev) {
               dev = alloc_netdev(....);
               ...;
               register_netdev(dev);
               ...;
               err = tun_attach(..);
            }


Only one thread is in tun_set_iff() at a time, but the other thread
could have attached the file to a device before the one in tun_attach().

Eric

  reply	other threads:[~2009-08-06 14:27 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-03 16:12 [RFC PATCH v1] tun: Cleanup error handling in tun_set_iff() Paul Moore
2009-08-04  4:16 ` David Miller
2009-08-05  5:32 ` Eric W. Biederman
2009-08-05 21:38   ` Paul Moore
2009-08-05 23:14     ` Eric W. Biederman
2009-08-06 18:20       ` Paul Moore
2009-08-07  0:00         ` Herbert Xu
2009-08-07 12:23           ` Paul Moore
2009-08-06 10:10     ` Herbert Xu
2009-08-06 10:21       ` Eric W. Biederman
2009-08-06 13:37         ` Herbert Xu
2009-08-06 14:27           ` Eric W. Biederman [this message]
2009-08-06 14:39             ` Herbert Xu
2009-08-06 15:02               ` Eric W. Biederman
2009-08-06 18:09                 ` Paul Moore
2009-08-06 18:41                   ` David Miller
2009-08-07  0:22                 ` Herbert Xu
2009-08-07  3:40                   ` David Miller
2009-08-07  4:22                     ` Eric W. Biederman
2009-08-10  4:52                       ` David Miller

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=m1ljlxj9vi.fsf@fess.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=paul.moore@hp.com \
    /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).