public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <andrea@suse.de>
To: David Mosberger <davidm@hpl.hp.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [patch] proposed fix for ptrace() SMP race
Date: Fri, 7 Sep 2001 02:19:00 +0200	[thread overview]
Message-ID: <20010907021900.L11329@athlon.random> (raw)
In-Reply-To: <200109062300.QAA27430@napali.hpl.hp.com>
In-Reply-To: <200109062300.QAA27430@napali.hpl.hp.com>; from davidm@hpl.hp.com on Thu, Sep 06, 2001 at 04:00:51PM -0700

On Thu, Sep 06, 2001 at 04:00:51PM -0700, David Mosberger wrote:
> There is currently a nasty race condition in ptrace().  The effect of

Last time I checked for such race it was looking ok (on x86). Do you
have a testcase to demonstrate it?

> this varies from one platform to another but, for example, on ia64, it
> could have the effect of corrupting the state of register f32-f127.
> The problem is that ptrace() uses the expression (child->state ==
> TASK_STOPPED) to determine whether or not a task has stopped
> execution.  On SMP, this is not sufficient because the task may still
> be executing while child->has_cpu is true.  This is easy to fix, but

but it cannot be running in "userspace" any longer once it is set to
TASK_STOPPED which should be the _only_ thing we care in ptrace. If it's
still running it's in its way to schedule() a few lines after the
setting of tsk->state to TASK_STOPPED and that's ok for ptrace.

> clearing child->cpus_allowed while ptrace() is running.  This should

abusing cpus_allowed to forbid scheduling is racy so quite unacceptable,
we want to preserve the cpus_allowed field for the administrator (he
could as well set it during the ptrace).

If on ia64 you really need to have switched the task away completly (not
only out of userspace) you could do this instead of messing with
cpus_allowed:

	if (not task_stopped)
		return
#ifdef CONFIG_SMP
	rmb(); /* read child->has_cpu after child->state */
	while (child->has_cpu);
	mb(); /* allowed to work on the task only when the task is been descheduled */
#endif

in ia64/kernel/ptrace.c

Actually one scary thing I can see in ptrace is the PTRACE_KILL case
that goes ahead doing the get_stack_long and put_stack_long even if the
task isn't out of userspace. I'd feel better with something like this:

--- 2.4.10pre4aa1/arch/i386/kernel/ptrace.c.~1~	Sat Jul 21 00:04:05 2001
+++ 2.4.10pre4aa1/arch/i386/kernel/ptrace.c	Fri Sep  7 02:14:45 2001
@@ -171,10 +171,8 @@
 	ret = -ESRCH;
 	if (!(child->ptrace & PT_PTRACED))
 		goto out_tsk;
-	if (child->state != TASK_STOPPED) {
-		if (request != PTRACE_KILL)
-			goto out_tsk;
-	}
+	if (child->state != TASK_STOPPED || child->state != TASK_ZOMBIE)
+		goto out_tsk;
 	if (child->p_pptr != current)
 		goto out_tsk;
 	switch (request) {


but OTOH I've no idea who is using PTRACE_KILL (but still it looks
saner or otherwise it means PTRACE_KILL implementation is at least
partly wrong anyways).

Andrea

  reply	other threads:[~2001-09-07  0:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-06 23:00 [patch] proposed fix for ptrace() SMP race David Mosberger
2001-09-07  0:19 ` Andrea Arcangeli [this message]
2001-09-07  0:40   ` David Mosberger
2001-09-07  1:28     ` Andrea Arcangeli
2001-09-07  1:41       ` Alan Cox
2001-09-07 13:34         ` Andrea Arcangeli
2001-09-07  5:21       ` David Mosberger
2001-09-07 13:28         ` Andrea Arcangeli
2001-09-07 15:35           ` David Mosberger
2001-09-08 17:11             ` Andrea Arcangeli
2001-09-10 17:20               ` David Mosberger
  -- strict thread matches above, loose matches on Subject: below --
2001-09-10 17:54 Manfred Spraul

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=20010907021900.L11329@athlon.random \
    --to=andrea@suse.de \
    --cc=davidm@hpl.hp.com \
    --cc=linux-kernel@vger.kernel.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