All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach
@ 2007-11-22 16:14 Oleg Nesterov
  2007-11-23 10:23 ` Alexey Dobriyan
  2007-12-11  1:36 ` Roland McGrath
  0 siblings, 2 replies; 4+ messages in thread
From: Oleg Nesterov @ 2007-11-22 16:14 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Alexey Dobriyan, Linus Torvalds, Roland McGrath,
	Scott James Remnant, linux-kernel

If the tracer went away (may_ptrace_stop() failed), ptrace_stop() drops tasklist
and then changes the ->state from TASK_TRACED to TASK_RUNNING.

This can fool another tracer which attaches to us in between. Change the ->state
under tasklist_lock to ensure that ptrace_check_attach() can't wrongly succeed.
Also, remove the unnecessary mb().

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

--- PT/kernel/signal.c~1_ptrace_stop	2007-11-21 21:41:02.000000000 +0300
+++ PT/kernel/signal.c	2007-11-22 16:59:35.000000000 +0300
@@ -1628,11 +1628,11 @@ static void ptrace_stop(int exit_code, i
 	} else {
 		/*
 		 * By the time we got the lock, our tracer went away.
-		 * Don't stop here.
+		 * Don't drop the lock yet, another tracer may come.
 		 */
-		read_unlock(&tasklist_lock);
-		set_current_state(TASK_RUNNING);
+		__set_current_state(TASK_RUNNING);
 		current->exit_code = nostop_code;
+		read_unlock(&tasklist_lock);
 	}
 
 	/*


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach
  2007-11-22 16:14 [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach Oleg Nesterov
@ 2007-11-23 10:23 ` Alexey Dobriyan
  2007-11-23 10:54   ` Oleg Nesterov
  2007-12-11  1:36 ` Roland McGrath
  1 sibling, 1 reply; 4+ messages in thread
From: Alexey Dobriyan @ 2007-11-23 10:23 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Linus Torvalds, Roland McGrath,
	Scott James Remnant, linux-kernel

On Thu, Nov 22, 2007 at 07:14:59PM +0300, Oleg Nesterov wrote:
> If the tracer went away (may_ptrace_stop() failed), ptrace_stop() drops tasklist
> and then changes the ->state from TASK_TRACED to TASK_RUNNING.
> 
> This can fool another tracer which attaches to us in between. Change the ->state
> under tasklist_lock to ensure that ptrace_check_attach() can't wrongly succeed.

ptrace_check_attach? Both do read_lock -- can run in parallel, so how can it help?

> --- PT/kernel/signal.c~1_ptrace_stop	2007-11-21 21:41:02.000000000 +0300
> +++ PT/kernel/signal.c	2007-11-22 16:59:35.000000000 +0300
> @@ -1628,11 +1628,11 @@ static void ptrace_stop(int exit_code, i
>  	} else {
>  		/*
>  		 * By the time we got the lock, our tracer went away.
> -		 * Don't stop here.
> +		 * Don't drop the lock yet, another tracer may come.
>  		 */
> -		read_unlock(&tasklist_lock);
> -		set_current_state(TASK_RUNNING);
> +		__set_current_state(TASK_RUNNING);
>  		current->exit_code = nostop_code;
> +		read_unlock(&tasklist_lock);
>  	}
>  
>  	/*


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach
  2007-11-23 10:23 ` Alexey Dobriyan
@ 2007-11-23 10:54   ` Oleg Nesterov
  0 siblings, 0 replies; 4+ messages in thread
From: Oleg Nesterov @ 2007-11-23 10:54 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: Andrew Morton, Linus Torvalds, Roland McGrath,
	Scott James Remnant, linux-kernel

On 11/23, Alexey Dobriyan wrote:
>
> On Thu, Nov 22, 2007 at 07:14:59PM +0300, Oleg Nesterov wrote:
> > If the tracer went away (may_ptrace_stop() failed), ptrace_stop() drops tasklist
> > and then changes the ->state from TASK_TRACED to TASK_RUNNING.
> > 
> > This can fool another tracer which attaches to us in between. Change the ->state
> > under tasklist_lock to ensure that ptrace_check_attach() can't wrongly succeed.
> 
> ptrace_check_attach? Both do read_lock -- can run in parallel,

Yep.

> so how can it help?

read_lock prevents ptrace_attach(), so the new tracer can't attach
and then do ptrace_check_attach().

Oleg.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach
  2007-11-22 16:14 [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach Oleg Nesterov
  2007-11-23 10:23 ` Alexey Dobriyan
@ 2007-12-11  1:36 ` Roland McGrath
  1 sibling, 0 replies; 4+ messages in thread
From: Roland McGrath @ 2007-12-11  1:36 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Andrew Morton, Alexey Dobriyan, Linus Torvalds,
	Scott James Remnant, linux-kernel

Your change looks correct to me.


Thanks,
Roland

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-11  1:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-22 16:14 [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach Oleg Nesterov
2007-11-23 10:23 ` Alexey Dobriyan
2007-11-23 10:54   ` Oleg Nesterov
2007-12-11  1:36 ` Roland McGrath

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.