public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm 1/2] ptrace_detach: the wrong wakeup breaks the ERESTARTxxx logic
@ 2009-02-13 10:54 Oleg Nesterov
  2009-02-20  3:47 ` Roland McGrath
  0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2009-02-13 10:54 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jerome Marchand, Roland McGrath, Denys Vlasenko, linux-kernel

Another ancient bug. Consider this trivial test-case,

	int main(void)
	{
		int pid = fork();

		if (pid) {
			ptrace(PTRACE_ATTACH, pid, NULL, NULL);
			wait(NULL);
			ptrace(PTRACE_DETACH, pid, NULL, NULL);
		} else {
			pause();
			printf("WE HAVE A KERNEL BUG!!!\n");
		}

		return 0;
	}

the child must not "escape" for sys_pause(), but it can and this was seen
in practice.

This is because ptrace_detach does:

	if (!child->exit_state)
		wake_up_process(child);

this wakeup can happen after this child has already restarted sys_pause(),
because it gets another wakeup from ptrace_untrace().

With or without this patch, perhaps sys_pause() needs a fix. But this
wakeup also breaks the SIGNAL_STOP_STOPPED logic in ptrace_untrace().

Remove this wakeup. The caller saw this task in TASK_TRACED state, and
unless it was SIGKILL'ed in between __ptrace_unlink()->ptrace_untrace()
should handle this case correctly. If it was SIGKILL'ed, we don't need
to wakup the dying tracee too.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>

--- 6.29-rc3/kernel/ptrace.c~1_KILL_WAKE	2009-02-13 11:06:04.000000000 +0100
+++ 6.29-rc3/kernel/ptrace.c	2009-02-13 11:06:56.000000000 +0100
@@ -301,11 +301,7 @@ int ptrace_detach(struct task_struct *ch
 	 */
 	if (child->ptrace) {
 		child->exit_code = data;
-
 		dead = __ptrace_detach(current, child);
-
-		if (!child->exit_state)
-			wake_up_process(child);
 	}
 	write_unlock_irq(&tasklist_lock);
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH -mm 1/2] ptrace_detach: the wrong wakeup breaks the ERESTARTxxx logic
  2009-02-13 10:54 [PATCH -mm 1/2] ptrace_detach: the wrong wakeup breaks the ERESTARTxxx logic Oleg Nesterov
@ 2009-02-20  3:47 ` Roland McGrath
  0 siblings, 0 replies; 2+ messages in thread
From: Roland McGrath @ 2009-02-20  3:47 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel

For TASK_TRACED, this wakeup is superfluous because of the one just done in
ptrace_untrace immediately prior.  For other cases it was always spurious
and the unconditional one looks quite wrong here.

Acked-By: Roland McGrath <roland@redhat.com>


Thanks,
Roland

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-20  3:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-13 10:54 [PATCH -mm 1/2] ptrace_detach: the wrong wakeup breaks the ERESTARTxxx logic Oleg Nesterov
2009-02-20  3:47 ` Roland McGrath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox