mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Andi Kleen <ak@muc.de>,
	linux-kernel@vger.kernel.org, torvalds@osdl.org, akpm@osdl.org
Subject: Re: [PATCH] cleanup ptrace stops and remove notify_parent
Date: Tue, 31 Aug 2004 18:56:21 -0700	[thread overview]
Message-ID: <200409010156.i811uLdd014564@magilla.sf.frob.com> (raw)
In-Reply-To: Roland McGrath's message of  Tuesday, 31 August 2004 17:27:54 -0700 <200409010027.i810RsWT001980@magilla.sf.frob.com>

I don't have a program like yours to test that it was broken with my patch
(now in 2.6.9-rc1-mm2).  But the following additional patch relative to
2.6.9-rc1-mm2 should do it.  I've tested that it doesn't create any new
problems.  I don't have something right handy that tests the case in
question, but you've said that you do.

This makes any ptrace operation that finds the target in TASK_STOPPED state
morph it into TASK_TRACED state before doing anything.  This necessitates
reverting the last_siginfo accesses to check instead of assume last_siginfo
is set, since it's no longer impossible to be in TASK_TRACED without being
stopped in ptrace_stop (though there are no associated races to worry
about).


Thanks,
Roland

--- linux-2.6.9-rc1-mm2/kernel/ptrace.c.~1~	2004-08-31 18:18:10.000000000 -0700
+++ linux-2.6.9-rc1-mm2/kernel/ptrace.c	2004-08-31 18:51:46.922556896 -0700
@@ -81,13 +81,20 @@ int ptrace_check_attach(struct task_stru
 	 * be changed by us so it's not changing right after this.
 	 */
 	read_lock(&tasklist_lock);
-	if ((child->ptrace & PT_PTRACED) && child->parent == current)
+	if ((child->ptrace & PT_PTRACED) && child->parent == current &&
+	    child->signal != NULL) {
 		ret = 0;
+		spin_lock_irq(&child->sighand->siglock);
+		if (child->state == TASK_STOPPED) {
+			child->state = TASK_TRACED;
+		} else if (child->state != TASK_TRACED && !kill) {
+			ret = -ESRCH;
+		}
+		spin_unlock_irq(&child->sighand->siglock);
+	}
 	read_unlock(&tasklist_lock);
 
 	if (!ret && !kill) {
-		if (child->state != TASK_TRACED)
-			return -ESRCH;
 		wait_task_inactive(child);
 	}
 
@@ -298,13 +305,15 @@ static int ptrace_setoptions(struct task
 
 static int ptrace_getsiginfo(struct task_struct *child, siginfo_t __user * data)
 {
-	BUG_ON(child->last_siginfo == NULL);
+	if (child->last_siginfo == NULL)
+		return -EINVAL;
 	return copy_siginfo_to_user(data, child->last_siginfo);
 }
 
 static int ptrace_setsiginfo(struct task_struct *child, siginfo_t __user * data)
 {
-	BUG_ON(child->last_siginfo == NULL);
+	if (child->last_siginfo == NULL)
+		return -EINVAL;
 	if (copy_from_user(child->last_siginfo, data, sizeof (siginfo_t)) != 0)
 		return -EFAULT;
 	return 0;

  reply	other threads:[~2004-09-01  1:56 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2z7vs-2F1-13@gated-at.bofh.it>
2004-08-31 10:00 ` Andi Kleen
2004-09-01  0:27   ` Roland McGrath
2004-09-01  1:56     ` Roland McGrath [this message]
2004-09-04 13:38       ` Andi Kleen
2004-08-31 15:59 Albert Cahalan
2004-08-31 23:54 ` Roland McGrath
2004-09-01  0:27   ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
2004-08-31  3:25 Roland McGrath
2004-08-31  3:43 ` Andrew Morton
2004-08-31  4:11   ` Roland McGrath
2004-08-31  4:26     ` Andrew Morton
2004-08-31  5:43       ` Roland McGrath
2004-08-31  4:27     ` Linus Torvalds
2004-08-31  4:50       ` Roland McGrath
2004-08-31 13:19       ` OGAWA Hirofumi
2004-08-31 13:56         ` Daniel Jacobowitz
2004-09-01  0:11         ` Roland McGrath
2004-09-01  4:25           ` OGAWA Hirofumi
2004-08-31  9:29     ` Christoph Hellwig
2004-08-31  9:43       ` Anton Blanchard
2004-09-01  0:00         ` Roland McGrath
2004-08-31  3:59 ` Roland McGrath
2004-08-31  4:22 ` Daniel Jacobowitz
2004-08-31  4:55   ` Roland McGrath
2004-08-31  4:59     ` Daniel Jacobowitz

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=200409010156.i811uLdd014564@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=ak@muc.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®