All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Denys Vlasenko <vda.linux@googlemail.com>, Tejun Heo <tj@kernel.org>
Cc: mtk.manpages@gmail.com,
	Jan Kratochvil <jan.kratochvil@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] ptrace: do_wait(traced_leader_killed_by_mt_exec) can block forever
Date: Thu, 21 Jul 2011 20:00:43 +0200	[thread overview]
Message-ID: <20110721180043.GB1319@redhat.com> (raw)
In-Reply-To: <20110721180019.GA1319@redhat.com>

Test-case:

	void *tfunc(void *arg)
	{
		execvp("true", NULL);
		return NULL;
	}

	int main(void)
	{
		int pid;

		if (fork()) {
			pthread_t t;

			kill(getpid(), SIGSTOP);

			pthread_create(&t, NULL, tfunc, NULL);

			for (;;)
				pause();
		}

		pid = getppid();
		assert(ptrace(PTRACE_ATTACH, pid, 0,0) == 0);

		while (wait(NULL) > 0)
			ptrace(PTRACE_CONT, pid, 0,0);

		return 0;
	}

It is racy, exit_notify() does __wake_up_parent() too. But in the
likely case it triggers the problem: de_thread() does release_task()
and the old leader goes away without the notification, the tracer
sleeps in do_wait() without children/tracees.

Change de_thread() to do __wake_up_parent(traced_leader->parent).
Since it is already EXIT_DEAD we can do this without ptrace_unlink(),
EXIT_DEAD threads do not exist from do_wait's pov.

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

 fs/exec.c |    8 ++++++++
 1 file changed, 8 insertions(+)

--- ptrace/fs/exec.c~ptrace_mt_exec_wait_hang	2011-07-17 20:16:36.000000000 +0200
+++ ptrace/fs/exec.c	2011-07-21 19:56:22.000000000 +0200
@@ -967,6 +967,14 @@ static int de_thread(struct task_struct 
 
 		BUG_ON(leader->exit_state != EXIT_ZOMBIE);
 		leader->exit_state = EXIT_DEAD;
+
+		/*
+		 * We are going to release_task()->ptrace_unlink() silently,
+		 * the tracer can sleep in do_wait(). EXIT_DEAD guarantees
+		 * the tracer wont't block again waiting for this thread.
+		 */
+		if (unlikely(leader->ptrace))
+			__wake_up_parent(leader, leader->parent);
 		write_unlock_irq(&tasklist_lock);
 
 		release_task(leader);


  reply	other threads:[~2011-07-21 18:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-21 11:09 [PATCH] man ptrace: add extended description of various ptrace quirks Denys Vlasenko
2011-07-21 16:51 ` Oleg Nesterov
2011-07-21 18:00   ` [PATCH 0/1] (Was: man ptrace: add extended description of various ptrace quirks) Oleg Nesterov
2011-07-21 18:00     ` Oleg Nesterov [this message]
2011-07-22  8:44       ` [PATCH 1/1] ptrace: do_wait(traced_leader_killed_by_mt_exec) can block forever Tejun Heo
2011-09-21  5:10   ` [PATCH] man ptrace: add extended description of various ptrace quirks Michael Kerrisk
2011-09-23  9:31     ` Denys Vlasenko
2011-09-25  6:10 ` Michael Kerrisk
2011-09-29 19:08 ` Michael Kerrisk
2011-09-30 14:14   ` Denys Vlasenko
2011-10-03  5:27     ` Michael Kerrisk
2011-10-03  5:27       ` Michael Kerrisk
     [not found]       ` <CAKgNAkj8tjBk1mXO6WhwUyeZDrRC5ECzHXLzPQ0PCpbr34D4_A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-13 22:02         ` Denys Vlasenko
2012-02-13 22:02           ` Denys Vlasenko
     [not found]           ` <CAK1hOcMEWnCysL1HRe+Z3Qfxg9+=tcY6YKWor7_bymNkPVSL+A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-26 18:25             ` Michael Kerrisk
2012-02-26 18:25               ` Michael Kerrisk
2012-02-26 18:42               ` Michael Kerrisk
     [not found]                 ` <CAKgNAkhZT=cGfAvenQpc7zLSzk6SPrKN_8FDLahK2QkKv3uhrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-27  0:58                   ` Denys Vlasenko
2012-02-27  0:58                     ` Denys Vlasenko
2012-03-05 17:33                     ` Michael Kerrisk (man-pages)
     [not found]   ` <CAKgNAkicbgpSLZE6Wn_5ickGojJuGd4x2vMUG0491OB+O1Z_HA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-09-30 14:28     ` Denys Vlasenko
2011-09-30 14:28       ` Denys Vlasenko
     [not found]       ` <CAK1hOcPqVYY93VFbDbMZ39iCr7VH+hP-bQT3u0SPJXmezN7H3Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-10-03  5:35         ` Michael Kerrisk
2011-10-03  5:35           ` Michael Kerrisk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110721180043.GB1319@redhat.com \
    --to=oleg@redhat.com \
    --cc=jan.kratochvil@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    --cc=tj@kernel.org \
    --cc=vda.linux@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.