ptrace: mv send-SIGSTOP from do_fork() to ptrace_init_task()
authorOleg Nesterov <oleg@redhat.com>
Fri, 8 Jul 2011 17:13:54 +0000 (19:13 +0200)
committerOleg Nesterov <oleg@redhat.com>
Sun, 17 Jul 2011 18:23:51 +0000 (20:23 +0200)
If the new child is traced, do_fork() adds the pending SIGSTOP.
It assumes that either it is traced because of auto-attach or the
tracer attached later, in both cases sigaddset/set_thread_flag is
correct even if SIGSTOP is already pending.

Now that we have PTRACE_SEIZE this is no longer right in the latter
case. If the tracer does PTRACE_SEIZE after copy_process() makes the
child visible the queued SIGSTOP is wrong.

We could check PT_SEIZED bit and change ptrace_attach() to set both
PT_PTRACED and PT_SEIZED bits simultaneously but see the next patch,
we need to know whether this child was auto-attached or not anyway.

So this patch simply moves this code to ptrace_init_task(), this
way we can never race with ptrace_attach().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
include/linux/ptrace.h
kernel/fork.c

index fd8669f..9b5d2c9 100644 (file)
@@ -227,6 +227,9 @@ static inline void ptrace_init_task(struct task_struct *child, bool ptrace)
        if (unlikely(ptrace) && current->ptrace) {
                child->ptrace = current->ptrace;
                __ptrace_link(child, current->parent);
        if (unlikely(ptrace) && current->ptrace) {
                child->ptrace = current->ptrace;
                __ptrace_link(child, current->parent);
+
+               sigaddset(&child->pending.signal, SIGSTOP);
+               set_tsk_thread_flag(child, TIF_SIGPENDING);
        }
 }
 
        }
 }
 
index 3c72a5b..4d4117e 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/swap.h>
 #include <linux/syscalls.h>
 #include <linux/jiffies.h>
 #include <linux/swap.h>
 #include <linux/syscalls.h>
 #include <linux/jiffies.h>
-#include <linux/tracehook.h>
 #include <linux/futex.h>
 #include <linux/compat.h>
 #include <linux/kthread.h>
 #include <linux/futex.h>
 #include <linux/compat.h>
 #include <linux/kthread.h>
@@ -1521,17 +1520,6 @@ long do_fork(unsigned long clone_flags,
 
                audit_finish_fork(p);
 
 
                audit_finish_fork(p);
 
-               /*
-                * Child is ready but hasn't started running yet.  Queue
-                * SIGSTOP if it's gonna be ptraced - it doesn't matter who
-                * attached/attaching to this task, the pending SIGSTOP is
-                * right in any case.
-                */
-               if (unlikely(p->ptrace)) {
-                       sigaddset(&p->pending.signal, SIGSTOP);
-                       set_tsk_thread_flag(p, TIF_SIGPENDING);
-               }
-
                /*
                 * We set PF_STARTING at creation in case tracing wants to
                 * use this to distinguish a fully live task from one that
                /*
                 * We set PF_STARTING at creation in case tracing wants to
                 * use this to distinguish a fully live task from one that