On Thu, Mar 25, 2021 at 07:27:35PM +0100, Oleg Nesterov wrote:
> On 03/25, Peter Zijlstra wrote:
> >
> >  static void ptrace_unfreeze_traced(struct task_struct *task)
> >  {
> > -   if (task->state != __TASK_TRACED)
> > +   if (READ_ONCE(task->__state) != __TASK_TRACED)
> >             return;
> 
> this change is correct,
> 
> > @@ -201,11 +201,11 @@ static void ptrace_unfreeze_traced(struct task_struct 
> > *task)
> >      * Recheck state under the lock to close this race.
> >      */
> >     spin_lock_irq(&task->sighand->siglock);
> > -   if (task->state == __TASK_TRACED) {
> > +   if (READ_ONCE(task->__state) == __TASK_TRACED) {
> 
> this too,
> 
> > @@ -240,7 +240,7 @@ static int ptrace_check_attach(struct task_struct 
> > *child, bool ignore_state)
> >      */
> >     read_lock(&tasklist_lock);
> >     if (child->ptrace && child->parent == current) {
> > -           WARN_ON(child->state == __TASK_TRACED);
> > +           WARN_ON(task_is_traced(child));
> >             /*
> >              * child->sighand can't be NULL, release_task()
> >              * does ptrace_unlink() before __exit_signal().
> > @@ -257,7 +257,7 @@ static int ptrace_check_attach(struct task_struct 
> > *child, bool ignore_state)
> >                      * ptrace_stop() changes ->state back to TASK_RUNNING,
> >                      * so we should not worry about leaking __TASK_TRACED.
> >                      */
> > -                   WARN_ON(child->state == __TASK_TRACED);
> > +                   WARN_ON(task_is_traced(child));
> 
> 
> the two above are not.
> 
> "state == __TASK_TRACED" and task_is_traced() is not the same thing.
> 
> "state == __TASK_TRACED" means that debugger changed the state from 
> TASK_TRACED
> to __TASK_TRACED (iow, removed TASK_WAKEKILL) to ensure the tracee can not 
> run,
> this doesn't affect task_is_traced().

Ah, my bad. I didn't expect the other bits to be relevant there,
should've read the code better. Will fix. Thanks!

Reply via email to