[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJuCfpFe0CEDXPQfHYATszZGKZa7h2Kjuym2yLYcdDFicGiAWg@mail.gmail.com>
Date: Fri, 19 Jul 2019 09:33:14 -0700
From: Suren Baghdasaryan <surenb@...gle.com>
To: Christian Brauner <christian@...uner.io>
Cc: Oleg Nesterov <oleg@...hat.com>,
"Joel Fernandes (Google)" <joel@...lfernandes.org>,
LKML <linux-kernel@...r.kernel.org>,
kernel-team <kernel-team@...roid.com>,
Andrea Arcangeli <aarcange@...hat.com>,
Andrew Morton <akpm@...ux-foundation.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Tejun Heo <tj@...nel.org>
Subject: Re: [PATCH RFC v1] pidfd: fix a race in setting exit_state for pidfd polling
On Fri, Jul 19, 2019 at 9:27 AM Christian Brauner <christian@...uner.io> wrote:
>
> On Fri, Jul 19, 2019 at 06:14:05PM +0200, Oleg Nesterov wrote:
> > it seems that I missed something else...
> >
> > On 07/17, Joel Fernandes (Google) wrote:
> > >
> > > @@ -1156,10 +1157,11 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
> > > ptrace_unlink(p);
> > >
> > > /* If parent wants a zombie, don't release it now */
> > > - state = EXIT_ZOMBIE;
> > > + p->exit_state = EXIT_ZOMBIE;
> > > if (do_notify_parent(p, p->exit_signal))
> > > - state = EXIT_DEAD;
> > > - p->exit_state = state;
> > > + p->exit_state = EXIT_DEAD;
> > > +
> > > + state = p->exit_state;
> > > write_unlock_irq(&tasklist_lock);
> >
> > why do you think we also need to change wait_task_zombie() ?
> >
> > pidfd_poll() only needs the exit_state != 0 check, we know that it
> > is not zero at this point. Why do we need to change exit_state before
> > do_notify_parent() ?
>
> Oh, because of?:
>
> /*
> * Move the task's state to DEAD/TRACE, only one thread can do this.
> */
> state = (ptrace_reparented(p) && thread_group_leader(p)) ?
> EXIT_TRACE : EXIT_DEAD;
> if (cmpxchg(&p->exit_state, EXIT_ZOMBIE, state) != EXIT_ZOMBIE)
> return 0;
>
> So exit_state will definitely be set in this scenario. Good point.
>
Yes, I think you are right. AFAIU in this code path p->exit_state
should always be equal to EXIT_TRACE because of the earlier cmpxchg()
call and the if condition before do_notify_parent(). That's of course
unless there is a chance that p->exit_state gets changed by some other
thread after cmpxchg() call and before do_notify_parent()... I'm not
that familiar with this code to say for sure that it's impossible. If
that can't happen I think we can remove this one but the change in
exit_notify() should definitely stay.
Thanks,
Suren.
> Christian
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@...roid.com.
>
Powered by blists - more mailing lists