public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] ptrace: fix possible zombie leak on PTRACE_DETACH
@ 2009-01-29  4:29 Oleg Nesterov
  2009-02-05  1:30 ` Roland McGrath
  0 siblings, 1 reply; 3+ messages in thread
From: Oleg Nesterov @ 2009-01-29  4:29 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Jerome Marchand, Roland McGrath, Denys Vlasenko, linux-kernel

When ptrace_detach() takes tasklist, the tracee can be SIGKILL'ed.
If it has already passed exit_notify() we can leak a zombie, because
a) ptracing disables the auto-reaping logic, and b) ->real_parent
was not notified about the child's death.

ptrace_detach() should follow the ptrace_exit's logic, change the
code accordingly.

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

--- 6.29-rc3/include/linux/ptrace.h~4_DETACH_FIX_ZOMBIE_LEAK	2009-01-12 23:07:48.000000000 +0100
+++ 6.29-rc3/include/linux/ptrace.h	2009-01-29 04:30:50.000000000 +0100
@@ -94,6 +94,7 @@ extern void ptrace_notify(int exit_code)
 extern void __ptrace_link(struct task_struct *child,
 			  struct task_struct *new_parent);
 extern void __ptrace_unlink(struct task_struct *child);
+extern int __ptrace_detach(struct task_struct *tracer, struct task_struct *p);
 extern void ptrace_fork(struct task_struct *task, unsigned long clone_flags);
 #define PTRACE_MODE_READ   1
 #define PTRACE_MODE_ATTACH 2
--- 6.29-rc3/kernel/ptrace.c~4_DETACH_FIX_ZOMBIE_LEAK	2009-01-29 03:24:51.000000000 +0100
+++ 6.29-rc3/kernel/ptrace.c	2009-01-29 04:39:48.000000000 +0100
@@ -237,6 +237,8 @@ out:
 
 int ptrace_detach(struct task_struct *child, unsigned int data)
 {
+	int dead = 0;
+
 	if (!valid_signal(data))
 		return -EIO;
 
@@ -244,18 +246,21 @@ int ptrace_detach(struct task_struct *ch
 	ptrace_disable(child);
 	clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 
-	/* protect against de_thread()->release_task() */
 	write_lock_irq(&tasklist_lock);
+	/* protect against de_thread()->release_task() */
 	if (child->ptrace) {
 		child->exit_code = data;
 
-		__ptrace_unlink(child);
+		dead = __ptrace_detach(current, child);
 
 		if (!child->exit_state)
 			wake_up_process(child);
 	}
 	write_unlock_irq(&tasklist_lock);
 
+	if (unlikely(dead))
+		release_task(child);
+
 	return 0;
 }
 


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

* Re: [PATCH 4/4] ptrace: fix possible zombie leak on PTRACE_DETACH
  2009-01-29  4:29 [PATCH 4/4] ptrace: fix possible zombie leak on PTRACE_DETACH Oleg Nesterov
@ 2009-02-05  1:30 ` Roland McGrath
  2009-02-05 14:41   ` Oleg Nesterov
  0 siblings, 1 reply; 3+ messages in thread
From: Roland McGrath @ 2009-02-05  1:30 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel

ACK on the change, though looks different if you put __ptrace_detach in
ptrace.c with the earliar patch, as I suggest.  Also, I think this warrants
a comment for the release_task call mentioning briefly what it means:

	/*
	 * The flag means __ptrace_detach() determined that this child
	 * was a zombie that should have been auto-reaped already.
	 * Don't leak it.
	 */
	if (unlikely(dead))
		release_task(child);


Thanks,
Roland

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

* Re: [PATCH 4/4] ptrace: fix possible zombie leak on PTRACE_DETACH
  2009-02-05  1:30 ` Roland McGrath
@ 2009-02-05 14:41   ` Oleg Nesterov
  0 siblings, 0 replies; 3+ messages in thread
From: Oleg Nesterov @ 2009-02-05 14:41 UTC (permalink / raw)
  To: Roland McGrath
  Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel

On 02/04, Roland McGrath wrote:
>
> ACK on the change, though looks different if you put __ptrace_detach in
> ptrace.c with the earliar patch, as I suggest.  Also, I think this warrants
> a comment for the release_task call mentioning briefly what it means:
> 
> 	/*
> 	 * The flag means __ptrace_detach() determined that this child
> 	 * was a zombie that should have been auto-reaped already.
> 	 * Don't leak it.
> 	 */
> 	if (unlikely(dead))
> 		release_task(child);

OK, will add this to the cleanup patch too.

Oleg.


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

end of thread, other threads:[~2009-02-05 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-29  4:29 [PATCH 4/4] ptrace: fix possible zombie leak on PTRACE_DETACH Oleg Nesterov
2009-02-05  1:30 ` Roland McGrath
2009-02-05 14:41   ` Oleg Nesterov

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