linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Prasanna Meda <pmeda@akamai.com>
To: Roland McGrath <roland@redhat.com>
Cc: akpm@osdl.org, linux-mm@kvack.org
Subject: Re: [patch] ptrace: unlocked access to last_siginfo (resending)
Date: Wed, 26 Jan 2005 19:36:05 -0800	[thread overview]
Message-ID: <41F861A5.1C21FE1@akamai.com> (raw)
In-Reply-To: <200501140746.j0E7kVf3008191@magilla.sf.frob.com>

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]

Roland McGrath wrote:

> > Since Roland changed now to wakeup tracee with kill, I guess this needs to be fixed.
> > http://linus.bkbits.net:8080/linux-2.5/gnupatch@41e3fe5fIRH-W3aDnXZgfQ-qIvuXYg
> Indeed, this change should go in.  I'd forgotten about this.  I don't think
> there are any other things we decided to leave one way or another based on
> the ptrace behavior that has now changed back again, but I might be
> forgetting others too.  Thanks for bringing it up.

  Thanks, but looks like we fixed only part of the problem. If the
  child is on the exit path and releases sighand, we need to check for
  its existence too.  The attached patch should work.


Thanks,
Prasanna.


[-- Attachment #2: ptrace_needs_tasklistlock.patch --]
[-- Type: text/plain, Size: 2329 bytes --]



Looks like we fixed only part of the problem earlier. When the child
moves away from ptrace notify and resets the last_siginfo, sighand lock
helps. But if the child goes further in exit and releases the sighand,
we need to test that case too.See ptrace_check_attach() and exit_sighand().
They also use the task_list_lock.


Signed-Off-by: Prasanna Meda <pmeda@akamai.com>


--- a/kernel/ptrace.c	Sun Jan 16 10:57:30 2005
+++ b/kernel/ptrace.c	Sun Jan 16 11:59:03 2005
@@ -320,32 +320,44 @@
 static int ptrace_getsiginfo(struct task_struct *child, siginfo_t __user * data)
 {
 	siginfo_t lastinfo;
+	int error = -ESRCH;
 
-	spin_lock_irq(&child->sighand->siglock);
-	if (likely(child->last_siginfo != NULL)) {
-		memcpy(&lastinfo, child->last_siginfo, sizeof (siginfo_t));
-		spin_unlock_irq(&child->sighand->siglock);
-		return copy_siginfo_to_user(data, &lastinfo);
+	read_lock_irq(&tasklist_lock);
+	if (likely(child->sighand != NULL)) {
+		error = -EINVAL;
+		spin_lock(&child->sighand->siglock);
+		if (likely(child->last_siginfo != NULL)) {
+			memcpy(&lastinfo, child->last_siginfo, sizeof (siginfo_t));
+			error = 0;
+		}
+		spin_unlock(&child->sighand->siglock);
 	}
-	spin_unlock_irq(&child->sighand->siglock);
-	return -EINVAL;
+	read_unlock_irq(&tasklist_lock);
+	if (!error)
+		return copy_siginfo_to_user(data, &lastinfo);
+	return error;
 }
 
 static int ptrace_setsiginfo(struct task_struct *child, siginfo_t __user * data)
 {
 	siginfo_t newinfo;
+	int error = -ESRCH;
 
-	if (copy_from_user(&newinfo, data, sizeof (siginfo_t)) != 0)
+	if (copy_from_user(&newinfo, data, sizeof (siginfo_t)))
 		return -EFAULT;
 
-	spin_lock_irq(&child->sighand->siglock);
-	if (likely(child->last_siginfo != NULL)) {
-		memcpy(child->last_siginfo, &newinfo, sizeof (siginfo_t));
-		spin_unlock_irq(&child->sighand->siglock);
-		return 0;
+	read_lock_irq(&tasklist_lock);
+	if (likely(child->sighand != NULL)) {
+		error = -EINVAL;
+		spin_lock(&child->sighand->siglock);
+		if (likely(child->last_siginfo != NULL)) {
+			memcpy(child->last_siginfo, &newinfo, sizeof (siginfo_t));
+			error = 0;
+		}
+		spin_unlock(&child->sighand->siglock);
 	}
-	spin_unlock_irq(&child->sighand->siglock);
-	return -EINVAL;
+	read_unlock_irq(&tasklist_lock);
+	return error;
 }
 
 int ptrace_request(struct task_struct *child, long request,

  reply	other threads:[~2005-01-27  3:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-12  3:11 pmeda
2005-01-14  7:46 ` Roland McGrath
2005-01-27  3:36   ` Prasanna Meda [this message]
2005-01-27  3:40     ` Roland McGrath
2005-01-27  6:30 Meda, Prasanna

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=41F861A5.1C21FE1@akamai.com \
    --to=pmeda@akamai.com \
    --cc=akpm@osdl.org \
    --cc=linux-mm@kvack.org \
    --cc=roland@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox