mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: bsegall@google.com
Cc: linux-kernel@vger.kernel.org,
	Roland McGrath <roland@hack.frob.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tejun Heo <tj@kernel.org>
Subject: Re: [PATCHv2] ptrace: fix PTRACE_LISTEN race corrupting task->state
Date: Wed, 5 Apr 2017 14:30:45 +0200	[thread overview]
Message-ID: <20170405123045.GA3824@redhat.com> (raw)
In-Reply-To: <xm26y3vfhmkp.fsf_-_@bsegall-linux.mtv.corp.google.com>

On 04/04, bsegall@google.com wrote:
>
> v2: slight clarification in comments, put the conditional around the
> whole wakeup area

Acked-by: Oleg Nesterov <oleg@redhat.com>

and I think this should go to -stable.

> Oleg mentioned a preference for making LISTEN unfreeze instead; I have
> no preference there,

Yes, but I won't insist if you prefer this more simple fix,

> just wanted to make sure that this doesn't get
> forgotten entirely.

And you are right, I forgot about this bug. Thanks!

Oleg.

>  kernel/ptrace.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/ptrace.c b/kernel/ptrace.c
> index 0af928712174..7cc49c3e73af 100644
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
> @@ -184,11 +184,17 @@ static void ptrace_unfreeze_traced(struct task_struct *task)
>
>         WARN_ON(!task->ptrace || task->parent != current);
>
> +       /*
> +        * PTRACE_LISTEN can allow ptrace_trap_notify to wake us up
> +        * remotely. Recheck state under the lock to close this race.
> +        */
>         spin_lock_irq(&task->sighand->siglock);
> -       if (__fatal_signal_pending(task))
> -               wake_up_state(task, __TASK_TRACED);
> -       else
> -               task->state = TASK_TRACED;
> +       if (task->state == __TASK_TRACED) {
> +               if (__fatal_signal_pending(task))
> +                       wake_up_state(task, __TASK_TRACED);
> +               else
> +                       task->state = TASK_TRACED;
> +       }
>         spin_unlock_irq(&task->sighand->siglock);
>  }
>
> --
> 2.12.2.715.g7642488e1d-goog
>

      parent reply	other threads:[~2017-04-05 12:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 18:47 [PATCH] " bsegall
2017-02-22 16:55 ` Oleg Nesterov
2017-02-22 17:03   ` Oleg Nesterov
2017-02-22 17:56   ` bsegall
2017-02-24 16:36 ` Oleg Nesterov
2017-02-27 18:08   ` bsegall
2017-04-04 21:47   ` [PATCHv2] " bsegall
2017-04-04 21:53     ` Andrew Morton
2017-04-05 12:36       ` Oleg Nesterov
2017-04-05 12:30     ` Oleg Nesterov [this message]

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=20170405123045.GA3824@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bsegall@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@hack.frob.com \
    --cc=tj@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

Powered by JetHome