The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@sw.ru>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roland McGrath <roland@redhat.com>,
	Scott James Remnant <scott@ubuntu.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH -mm 1/2] ptrace_stop: fix the race with ptrace detach+attach
Date: Fri, 23 Nov 2007 13:23:51 +0300	[thread overview]
Message-ID: <20071123102351.GD6240@localhost.sw.ru> (raw)
In-Reply-To: <20071122161459.GA5973@tv-sign.ru>

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);
>  	}
>  
>  	/*


  reply	other threads:[~2007-11-23 10:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2007-11-23 10:54   ` Oleg Nesterov
2007-12-11  1:36 ` 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=20071123102351.GD6240@localhost.sw.ru \
    --to=adobriyan@sw.ru \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    --cc=roland@redhat.com \
    --cc=scott@ubuntu.com \
    --cc=torvalds@linux-foundation.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