public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tytso@mit.edu
To: Michel Lespinasse <walken@google.com>
Cc: Salman <sqazi@google.com>,
	peterz@infradead.org, mingo@elte.hu, akpm@inux-foundation.org,
	linux-kernel@vger.kernel.org, tytso@google.com
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be reused immediately.
Date: Wed, 9 Jun 2010 08:37:04 -0400	[thread overview]
Message-ID: <20100609123704.GE6529@thunk.org> (raw)
In-Reply-To: <20100609114903.GA9223@google.com>

On Wed, Jun 09, 2010 at 04:49:03AM -0700, Michel Lespinasse wrote:
> You should make sure to handle pid wrap-around for this last/pid comparison.
> I think proper way to do that would be:

Good point!  I forgot about checking for pid wrap-around.

> The last_read == pid case is also interesting - it means another
> thread found the same pid, forked a child with that pid, and the
> child exited already (since the bitmap was cleared).  However we
> don't need to handle that case - first, that race is much less
> likely to happen, and second, the duplicate pid would be returned in
> two separate tasks - so this would not cause problems in bash as in
> your example.

In order for that to happen, all of this would have to happen between
the time that last_pid was initially sampled at the very beginning of
alloc_pidmap().  Could that happen?  I think it could, if kzalloc()
took a very long time to run, and the scheduler was _very_ unfair.  We
could try to guard against that by checking to see if last_pid has
changed after allocating map->page (in the unlikely case of !map->page
being NULL in the first place) and if so, restarting alloc_pidmap() by
jumping back to the beginning of the function.

Could that happen with bash?  I'm not as confident as you that it
could never happen.  The fact that we saw the race in the first place
in bash means that it could still happen in this case, I think.  In
any case, if we have two processes getting the same pid in the absence
of a fork, that would be a bad thing and could lead to all sorts of
confusion, so it's probably a good thing to guard against even if it
is a rare case.

BTW, Salman, I haven't seen it, but I vaguely remember in the mail
exchange with the person who reported this that we have a C/C++
reproduction case?  If it's small enough, it might be a good idea to
include it in the patch description.

						- Ted

  reply	other threads:[~2010-06-09 12:37 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-09  6:24 [PATCH] Fix a race in pid generation that causes pids to be reused immediately Salman
2010-06-09  6:53 ` Andi Kleen
2010-06-09  9:48 ` Ingo Molnar
2010-06-09 15:39   ` Linus Torvalds
2010-06-09 15:50     ` tytso
2010-06-09 16:06       ` Linus Torvalds
2010-06-09 17:10         ` tytso
2010-06-09 17:23           ` Linus Torvalds
2010-06-09 17:25             ` Linus Torvalds
2010-06-09 17:34               ` tytso
2010-06-09 17:43                 ` Linus Torvalds
2010-06-09 17:47                   ` tytso
2010-06-09 18:09                     ` Salman Qazi
2010-06-09 11:49 ` Michel Lespinasse
2010-06-09 12:37   ` tytso [this message]
2010-06-09 12:17 ` tytso
  -- strict thread matches above, loose matches on Subject: below --
2010-06-09 21:00 Salman
2010-06-09 21:21 ` Linus Torvalds
2010-06-09 21:33   ` Peter Zijlstra
2010-06-09 22:20     ` Linus Torvalds
2010-06-09 22:27       ` Linus Torvalds
2010-06-10  0:08         ` Salman Qazi
2010-06-10  0:20           ` Linus Torvalds
     [not found]             ` <AANLkTilXJ0X2qxD9cNTlLayKzySEZu1HEZUWu--Go8kw@mail.gmail.com>
2010-06-10  5:55               ` Salman Qazi
2010-06-10 16:39                 ` Linus Torvalds
2010-06-10 20:09 Salman
2010-06-10 20:38 ` tytso
2010-06-10 21:04   ` Salman Qazi
2010-06-10 21:24 Salman
2010-06-11 17:17 Salman
2010-06-11 17:44 ` Linus Torvalds
2010-06-11 22:49   ` Salman
2010-06-11 23:07     ` Linus Torvalds
2010-06-14 23:58     ` Andrew Morton
2010-06-15  0:56       ` tytso
2010-06-15  1:55         ` Andrew Morton
2010-06-15  3:26           ` Paul Mackerras
2010-06-15  4:21             ` Andrew Morton
2010-06-15  4:38               ` Eric Dumazet
2010-06-15  6:57               ` Benjamin Herrenschmidt
2010-06-15  7:25               ` Paul Mackerras
2010-06-15 12:56           ` tytso
2010-06-15 13:06             ` Kyle McMartin
2010-06-15 14:35           ` Peter Zijlstra
2010-06-15 19:37             ` Andrew Morton

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=20100609123704.GE6529@thunk.org \
    --to=tytso@mit.edu \
    --cc=akpm@inux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=sqazi@google.com \
    --cc=tytso@google.com \
    --cc=walken@google.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