All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Matt Fleming <matt@console-pimps.org>
Cc: Tejun Heo <tj@kernel.org>,
	vda.linux@googlemail.com, jan.kratochvil@redhat.com,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, indan@nul.nu, bdonlan@gmail.com,
	pedro@codesourcery.com
Subject: Re: [PATCH 5/5] ptrace: implement PTRACE_LISTEN
Date: Fri, 23 Sep 2011 14:26:34 +0200	[thread overview]
Message-ID: <20110923122634.GA28898@redhat.com> (raw)
In-Reply-To: <1316776650.5262.26.camel@mfleming-mobl1.ger.corp.intel.com>

On 09/23, Matt Fleming wrote:
>
> On Tue, 2011-06-14 at 11:20 +0200, Tejun Heo wrote:
>
> [...]
>
> > +	case PTRACE_LISTEN:
> > +		/*
> > +		 * Listen for events.  Tracee must be in STOP.  It's not
> > +		 * resumed per-se but is not considered to be in TRACED by
> > +		 * wait(2) or ptrace(2).  If an async event (e.g. group
> > +		 * stop state change) happens, tracee will enter STOP trap
> > +		 * again.  Alternatively, ptracer can issue INTERRUPT to
> > +		 * finish listening and re-trap tracee into STOP.
> > +		 */
> > +		if (unlikely(!seized || !lock_task_sighand(child, &flags)))
> > +			break;
> > +
> > +		si = child->last_siginfo;
> > +		if (unlikely(!si || si->si_code >> 8 != PTRACE_EVENT_STOP))
> > +			break;
>
> I've only just noticed this. You really don't want to break out of the
> switch while holding sighand->siglock. This should read,
>
> 		if (unlikely(!si || si->si_code >> 8 != PTRACE_EVENT_STOP)) {
> 			unlock_task_sighand(child, &flags);
>			break;

OOOPS!!! Thanks... or perhaps the patch below.

This is must have for 3.1. I'll test it and send to Linus.

Good catch, thanks.

And I seem to see other "should be fixed before 3.1" problems in the
jobctl code.

Oleg.

--- x/kernel/ptrace.c
+++ x/kernel/ptrace.c
@@ -744,20 +744,17 @@ int ptrace_request(struct task_struct *c
 			break;
 
 		si = child->last_siginfo;
-		if (unlikely(!si || si->si_code >> 8 != PTRACE_EVENT_STOP))
-			break;
-
-		child->jobctl |= JOBCTL_LISTENING;
-
-		/*
-		 * If NOTIFY is set, it means event happened between start
-		 * of this trap and now.  Trigger re-trap immediately.
-		 */
-		if (child->jobctl & JOBCTL_TRAP_NOTIFY)
-			signal_wake_up(child, true);
-
+		if (likely(si && (si->si_code >> 8) == PTRACE_EVENT_STOP)) {
+			child->jobctl |= JOBCTL_LISTENING;
+			/*
+			 * If NOTIFY is set, it means event happened between start
+			 * of this trap and now.  Trigger re-trap immediately.
+			 */
+			if (child->jobctl & JOBCTL_TRAP_NOTIFY)
+				signal_wake_up(child, true);
+			ret = 0;
+		}
 		unlock_task_sighand(child, &flags);
-		ret = 0;
 		break;
 
 	case PTRACE_DETACH:	 /* detach a process that was attached. */


  reply	other threads:[~2011-09-23 12:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-14  9:20 [PATCHSET ptrace] ptrace: implement PTRACE_SEIZE/INTERRUPT and group stop notification, take#5 Tejun Heo
2011-06-14  9:20 ` [PATCH 1/5] job control: introduce JOBCTL_TRAP_STOP and use it for group stop trap Tejun Heo
2011-06-14  9:20 ` [PATCH 2/5] ptrace: implement PTRACE_SEIZE Tejun Heo
2011-06-18  7:55   ` Denys Vlasenko
2011-06-18  7:59     ` Denys Vlasenko
2011-06-18  8:35       ` Tejun Heo
2011-06-18  8:57         ` Denys Vlasenko
2011-06-18  9:04           ` Tejun Heo
2011-06-18  8:30     ` Tejun Heo
2011-06-18  8:58       ` Denys Vlasenko
2011-06-14  9:20 ` [PATCH 3/5] ptrace: implement PTRACE_INTERRUPT Tejun Heo
2011-06-14  9:20 ` [PATCH 4/5] ptrace: implement TRAP_NOTIFY and use it for group stop events Tejun Heo
2011-06-16 19:51   ` Oleg Nesterov
2011-06-17 15:12     ` Tejun Heo
2011-06-17 18:31       ` Oleg Nesterov
2011-06-14  9:20 ` [PATCH 5/5] ptrace: implement PTRACE_LISTEN Tejun Heo
2011-09-23 11:17   ` Matt Fleming
2011-09-23 12:26     ` Oleg Nesterov [this message]
2011-06-16 19:44 ` [PATCHSET ptrace] ptrace: implement PTRACE_SEIZE/INTERRUPT and group stop notification, take#5 Oleg Nesterov

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=20110923122634.GA28898@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bdonlan@gmail.com \
    --cc=indan@nul.nu \
    --cc=jan.kratochvil@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@console-pimps.org \
    --cc=pedro@codesourcery.com \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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.