Skip to content

Commit dcace06

Browse files
committed
ptrace: mv send-SIGSTOP from do_fork() to ptrace_init_task()
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>
1 parent 6634ae1 commit dcace06

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

‎include/linux/ptrace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ static inline void ptrace_init_task(struct task_struct *child, bool ptrace)
227227
if (unlikely(ptrace) && current->ptrace) {
228228
child->ptrace = current->ptrace;
229229
__ptrace_link(child, current->parent);
230+
231+
sigaddset(&child->pending.signal, SIGSTOP);
232+
set_tsk_thread_flag(child, TIF_SIGPENDING);
230233
}
231234
}
232235

‎kernel/fork.c‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include <linux/swap.h>
3838
#include <linux/syscalls.h>
3939
#include <linux/jiffies.h>
40-
#include <linux/tracehook.h>
4140
#include <linux/futex.h>
4241
#include <linux/compat.h>
4342
#include <linux/kthread.h>
@@ -1521,17 +1520,6 @@ long do_fork(unsigned long clone_flags,
15211520

15221521
audit_finish_fork(p);
15231522

1524-
/*
1525-
* Child is ready but hasn't started running yet. Queue
1526-
* SIGSTOP if it's gonna be ptraced - it doesn't matter who
1527-
* attached/attaching to this task, the pending SIGSTOP is
1528-
* right in any case.
1529-
*/
1530-
if (unlikely(p->ptrace)) {
1531-
sigaddset(&p->pending.signal, SIGSTOP);
1532-
set_tsk_thread_flag(p, TIF_SIGPENDING);
1533-
}
1534-
15351523
/*
15361524
* We set PF_STARTING at creation in case tracing wants to
15371525
* use this to distinguish a fully live task from one that

0 commit comments

Comments
 (0)