From: Joel Fernandes <joel@joelfernandes.org>
To: Christian Brauner <christian@brauner.io>
Cc: linux-kernel@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>,
kernel-team@android.com, Andrea Arcangeli <aarcange@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Oleg Nesterov <oleg@redhat.com>, Tejun Heo <tj@kernel.org>,
jannh@google.com
Subject: Re: [PATCH RFC v1] pidfd: fix a race in setting exit_state for pidfd polling
Date: Wed, 17 Jul 2019 16:51:12 -0400 [thread overview]
Message-ID: <20190717205112.GC72146@google.com> (raw)
In-Reply-To: <20190717175556.axe2pne7lcrkmtzr@brauner.io>
On Wed, Jul 17, 2019 at 07:55:57PM +0200, Christian Brauner wrote:
> On Wed, Jul 17, 2019 at 01:21:00PM -0400, Joel Fernandes wrote:
> > From: Suren Baghdasaryan <surenb@google.com>
> >
> > There is a race between reading task->exit_state in pidfd_poll and writing
> > it after do_notify_parent calls do_notify_pidfd. Expected sequence of
> > events is:
> >
> > CPU 0 CPU 1
> > ------------------------------------------------
> > exit_notify
> > do_notify_parent
> > do_notify_pidfd
> > tsk->exit_state = EXIT_DEAD
> > pidfd_poll
> > if (tsk->exit_state)
> >
> > However nothing prevents the following sequence:
> >
> > CPU 0 CPU 1
> > ------------------------------------------------
> > exit_notify
> > do_notify_parent
> > do_notify_pidfd
> > pidfd_poll
> > if (tsk->exit_state)
> > tsk->exit_state = EXIT_DEAD
> >
> > This causes a polling task to wait forever, since poll blocks because
> > exit_state is 0 and the waiting task is not notified again. A stress
> > test continuously doing pidfd poll and process exits uncovered this bug,
> > and the below patch fixes it.
> >
> > To fix this, we set tsk->exit_state before calling do_notify_pidfd.
> >
> > Cc: kernel-team@android.com
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
>
> That means in such a situation other users will see EXIT_ZOMBIE where
> they didn't see that before until after the parent failed to get
> notified.
>
> That's a rather subtle internal change. I was worried about
> __ptrace_detach() since it explicitly checks for EXIT_ZOMBIE but it
> seems to me that this is fine since we hold write_lock_irq(&tasklist_lock);
> at the point when we do set p->exit_signal.
Right.
> Acked-by: Christian Brauner <christian@brauner.io>
Thanks.
> Once Oleg confirms that I'm right not to worty I'll pick this up.
Ok.
next prev parent reply other threads:[~2019-07-17 20:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-17 17:21 [PATCH RFC v1] pidfd: fix a race in setting exit_state for pidfd polling Joel Fernandes (Google)
2019-07-17 17:55 ` Christian Brauner
2019-07-17 18:09 ` Suren Baghdasaryan
2019-07-17 20:47 ` Joel Fernandes
2019-07-18 10:09 ` Christian Brauner
2019-07-17 20:51 ` Joel Fernandes [this message]
2019-07-18 10:17 ` Christian Brauner
2019-07-18 16:05 ` Suren Baghdasaryan
2019-07-18 15:00 ` Oleg Nesterov
2019-07-19 16:14 ` Oleg Nesterov
2019-07-19 16:27 ` Christian Brauner
2019-07-19 16:33 ` Suren Baghdasaryan
2019-07-19 16:51 ` Joel Fernandes
2019-07-19 16:53 ` Christian Brauner
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=20190717205112.GC72146@google.com \
--to=joel@joelfernandes.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=christian@brauner.io \
--cc=ebiederm@xmission.com \
--cc=jannh@google.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=surenb@google.com \
--cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.