Commit 087eb437 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

ptrace: tracehook_report_clone: fix false positives

The "trace || CLONE_PTRACE" check in tracehook_report_clone() is not right,

- If the untraced task does clone(CLONE_PTRACE) the new child is not traced,
  we must not queue SIGSTOP.

- If we forked the traced task, but the tracer exits and untraces both the
  forking task and the new child (after copy_process() drops tasklist_lock),
  we should not queue SIGSTOP too.

Change the code to check task_ptrace() != 0 instead. This is still racy, but
the race is harmless.

We can race with another tracer attaching to this child, or the tracer can
exit and detach in parallel. But giwen that we didn't do wake_up_new_task()
yet, the child must have the pending SIGSTOP anyway.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarRoland McGrath <roland@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b87297fb
...@@ -259,14 +259,12 @@ static inline void tracehook_finish_clone(struct task_struct *child, ...@@ -259,14 +259,12 @@ static inline void tracehook_finish_clone(struct task_struct *child,
/** /**
* tracehook_report_clone - in parent, new child is about to start running * tracehook_report_clone - in parent, new child is about to start running
* @trace: return value from tracehook_prepare_clone()
* @regs: parent's user register state * @regs: parent's user register state
* @clone_flags: flags from parent's system call * @clone_flags: flags from parent's system call
* @pid: new child's PID in the parent's namespace * @pid: new child's PID in the parent's namespace
* @child: new child task * @child: new child task
* *
* Called after a child is set up, but before it has been started * Called after a child is set up, but before it has been started running.
* running. @trace is the value returned by tracehook_prepare_clone().
* This is not a good place to block, because the child has not started * This is not a good place to block, because the child has not started
* yet. Suspend the child here if desired, and then block in * yet. Suspend the child here if desired, and then block in
* tracehook_report_clone_complete(). This must prevent the child from * tracehook_report_clone_complete(). This must prevent the child from
...@@ -276,13 +274,14 @@ static inline void tracehook_finish_clone(struct task_struct *child, ...@@ -276,13 +274,14 @@ static inline void tracehook_finish_clone(struct task_struct *child,
* *
* Called with no locks held, but the child cannot run until this returns. * Called with no locks held, but the child cannot run until this returns.
*/ */
static inline void tracehook_report_clone(int trace, struct pt_regs *regs, static inline void tracehook_report_clone(struct pt_regs *regs,
unsigned long clone_flags, unsigned long clone_flags,
pid_t pid, struct task_struct *child) pid_t pid, struct task_struct *child)
{ {
if (unlikely(trace) || unlikely(clone_flags & CLONE_PTRACE)) { if (unlikely(task_ptrace(child))) {
/* /*
* The child starts up with an immediate SIGSTOP. * It doesn't matter who attached/attaching to this
* task, the pending SIGSTOP is right in any case.
*/ */
sigaddset(&child->pending.signal, SIGSTOP); sigaddset(&child->pending.signal, SIGSTOP);
set_tsk_thread_flag(child, TIF_SIGPENDING); set_tsk_thread_flag(child, TIF_SIGPENDING);
......
...@@ -1409,7 +1409,7 @@ long do_fork(unsigned long clone_flags, ...@@ -1409,7 +1409,7 @@ long do_fork(unsigned long clone_flags,
} }
audit_finish_fork(p); audit_finish_fork(p);
tracehook_report_clone(trace, regs, clone_flags, nr, p); tracehook_report_clone(regs, clone_flags, nr, p);
/* /*
* We set PF_STARTING at creation in case tracing wants to * We set PF_STARTING at creation in case tracing wants to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment