Skip to content

Commit

Permalink
ptrace_stop: fix the race with ptrace detach+attach
Browse files Browse the repository at this point in the history
If the tracer went away (may_ptrace_stop() failed), ptrace_stop() drops
tasklist and then changes the ->state from TASK_TRACED to TASK_RUNNING.

This can fool another tracer which attaches to us in between.  Change the
->state under tasklist_lock to ensure that ptrace_check_attach() can't wrongly
succeed.  Also, remove the unnecessary mb().

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Roland McGrath <roland@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Feb 8, 2008
1 parent c0c0b64 commit 6405f7f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,11 @@ static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
} else {
/*
* By the time we got the lock, our tracer went away.
* Don't stop here.
* Don't drop the lock yet, another tracer may come.
*/
read_unlock(&tasklist_lock);
set_current_state(TASK_RUNNING);
__set_current_state(TASK_RUNNING);
current->exit_code = nostop_code;
read_unlock(&tasklist_lock);
}

/*
Expand Down

0 comments on commit 6405f7f

Please sign in to comment.