• Roland McGrath's avatar
    [PATCH] Wake up signalled tasks when exiting ptrace · 403f2912
    Roland McGrath authored
    In general it is not safe to do any non-ptrace wakeup of a thread in
    TASK_TRACED, because the waking thread could race with a ptrace call
    that could be doing things like mucking directly with its kernel stack. 
    
    AFAIK noone has established that whatever clobberation ptrace can do to
    a running thread is safe even if it will never return to user mode, so
    we can't allow this even for SIGKILL.
    
    What we _can_ safely do is make a thread switching out of TASK_TRACED
    resume rather than sitting in TASK_STOPPED if it has a pending SIGKILL
    or SIGCONT.  The following patch does this.
    
    This should be sufficient for the shutdown case.  When killing all
    processes, if the tracer gets killed first, the tracee goes into
    TASK_STOPPED and will be woken and killed by the SIGKILL (same as
    before).  If the tracee gets killed first, it gets a pending SIGKILL and
    doesn't wake up immediately--but, now, when the tracer gets killed, the
    tracee will then wake up to die. 
    
    This will also fix the (same) situations that can arise now where you
    have used gdb (or whatever ptrace caller), killed -9 the gdb and the
    process being debugged, but still have to kill -CONT the process before
    it goes away (now it should just go away either the first time or when
    you kill gdb). 
    Signed-off-by: default avatarRoland McGrath <roland@redhat.com>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    403f2912
ptrace.c 8.25 KB