Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Oleg Nesterov <oleg@redhat.com>
Acked-by: Roland McGrath <roland@redhat.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
087eb437 b87297fb

+6 -7
+5 -6
include/linux/tracehook.h
··· 259 259 260 260 /** 261 261 * tracehook_report_clone - in parent, new child is about to start running 262 - * @trace: return value from tracehook_prepare_clone() 263 262 * @regs: parent's user register state 264 263 * @clone_flags: flags from parent's system call 265 264 * @pid: new child's PID in the parent's namespace 266 265 * @child: new child task 267 266 * 268 - * Called after a child is set up, but before it has been started 269 - * running. @trace is the value returned by tracehook_prepare_clone(). 267 + * Called after a child is set up, but before it has been started running. 270 268 * This is not a good place to block, because the child has not started 271 269 * yet. Suspend the child here if desired, and then block in 272 270 * tracehook_report_clone_complete(). This must prevent the child from ··· 274 276 * 275 277 * Called with no locks held, but the child cannot run until this returns. 276 278 */ 277 - static inline void tracehook_report_clone(int trace, struct pt_regs *regs, 279 + static inline void tracehook_report_clone(struct pt_regs *regs, 278 280 unsigned long clone_flags, 279 281 pid_t pid, struct task_struct *child) 280 282 { 281 - if (unlikely(trace) || unlikely(clone_flags & CLONE_PTRACE)) { 283 + if (unlikely(task_ptrace(child))) { 282 284 /* 283 - * The child starts up with an immediate SIGSTOP. 285 + * It doesn't matter who attached/attaching to this 286 + * task, the pending SIGSTOP is right in any case. 284 287 */ 285 288 sigaddset(&child->pending.signal, SIGSTOP); 286 289 set_tsk_thread_flag(child, TIF_SIGPENDING);
+1 -1
kernel/fork.c
··· 1409 1409 } 1410 1410 1411 1411 audit_finish_fork(p); 1412 - tracehook_report_clone(trace, regs, clone_flags, nr, p); 1412 + tracehook_report_clone(regs, clone_flags, nr, p); 1413 1413 1414 1414 /* 1415 1415 * We set PF_STARTING at creation in case tracing wants to