From: Oleg Nesterov <oleg@tv-sign.ru>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Roland McGrath <roland@redhat.com>,
Scott James Remnant <scott@ubuntu.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH -mm 4/2] ptrace_stop: fix racy nonstop_code setting
Date: Thu, 22 Nov 2007 20:56:22 +0300 [thread overview]
Message-ID: <20071122175622.GA7051@tv-sign.ru> (raw)
If the tracer is gone and we are not going to stop, ptrace_stop() sets
->exit_code = nostop_code. However, the tracer could actually clear the
exit code before detaching. In that case get_signal_to_deliver() "resends"
the signal which was cancelled by the debugger. For example, it is possible
that a quick PTRACE_ATTACH + PTRACE_DETACH can leave the tracee in STOPPED
state.
Change the behaviour of ptrace_stop(). If the caller is ptrace notify(), we
should always clear ->exit_code. If the caller is get_signal_to_deliver(), we
should not touch it at all. To do so, change the nonstop_code parameter to
"bool clear_code" and change the callers accordingly.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- PT/kernel/signal.c~4_non_stop 2007-11-22 16:59:35.000000000 +0300
+++ PT/kernel/signal.c 2007-11-22 20:29:11.000000000 +0300
@@ -1601,10 +1601,10 @@ static inline int may_ptrace_stop(void)
* That makes it a way to test a stopped process for
* being ptrace-stopped vs being job-control-stopped.
*
- * If we actually decide not to stop at all because the tracer is gone,
- * we leave nostop_code in current->exit_code.
+ * If we actually decide not to stop at all because the tracer
+ * is gone, we keep current->exit_code unless clear_code.
*/
-static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
+static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
{
/*
* If there is a group stop in progress,
@@ -1631,7 +1631,8 @@ static void ptrace_stop(int exit_code, i
* Don't drop the lock yet, another tracer may come.
*/
__set_current_state(TASK_RUNNING);
- current->exit_code = nostop_code;
+ if (clear_code)
+ current->exit_code = 0;
read_unlock(&tasklist_lock);
}
@@ -1665,7 +1666,7 @@ void ptrace_notify(int exit_code)
/* Let the debugger run. */
spin_lock_irq(¤t->sighand->siglock);
- ptrace_stop(exit_code, 0, &info);
+ ptrace_stop(exit_code, 1, &info);
spin_unlock_irq(¤t->sighand->siglock);
}
@@ -1813,7 +1814,7 @@ relock:
ptrace_signal_deliver(regs, cookie);
/* Let the debugger run. */
- ptrace_stop(signr, signr, info);
+ ptrace_stop(signr, 0, info);
/* We're back. Did the debugger cancel the sig? */
signr = current->exit_code;
next reply other threads:[~2007-11-22 17:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-22 17:56 Oleg Nesterov [this message]
2007-12-11 1:41 ` Roland McGrath
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=20071122175622.GA7051@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@redhat.com \
--cc=scott@ubuntu.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
all inboxes | Powered by JetHome®