Skip to content

Commit

Permalink
ptrace: fix exit_ptrace() vs ptrace_traceme() race
Browse files Browse the repository at this point in the history
Pointed out by Roland.  The bug was recently introduced by me in
"forget_original_parent: split out the un-ptrace part", commit
39c626a.

Since that patch we have a window after exit_ptrace() drops tasklist and
before forget_original_parent() takes it again.  In this window the child
can do ptrace(PTRACE_TRACEME) and nobody can untrace this child after
that.

Change ptrace_traceme() to not attach to the exiting ->real_parent.  We
don't report the error in this case, we pretend we attach right before
->real_parent calls exit_ptrace() which should untrace us anyway.

Signed-off-by: Oleg Nesterov <[email protected]>
Acked-by: Roland McGrath <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Apr 13, 2009
1 parent 7b102d0 commit f1671f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,11 @@ int ptrace_traceme(void)
ret = security_ptrace_traceme(current->parent);

/*
* Set the ptrace bit in the process ptrace flags.
* Then link us on our parent's ptraced list.
* Check PF_EXITING to ensure ->real_parent has not passed
* exit_ptrace(). Otherwise we don't report the error but
* pretend ->real_parent untraces us right after return.
*/
if (!ret) {
if (!ret && !(current->real_parent->flags & PF_EXITING)) {
current->ptrace |= PT_PTRACED;
__ptrace_link(current, current->real_parent);
}
Expand Down

0 comments on commit f1671f6

Please sign in to comment.