Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755180AbdDEMb1 (ORCPT ); Wed, 5 Apr 2017 08:31:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47976 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752808AbdDEMau (ORCPT ); Wed, 5 Apr 2017 08:30:50 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0CAB361E4B Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=oleg@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0CAB361E4B Date: Wed, 5 Apr 2017 14:30:45 +0200 From: Oleg Nesterov To: bsegall@google.com Cc: linux-kernel@vger.kernel.org, Roland McGrath , Andrew Morton , Tejun Heo Subject: Re: [PATCHv2] ptrace: fix PTRACE_LISTEN race corrupting task->state Message-ID: <20170405123045.GA3824@redhat.com> References: <20170224163611.GA24902@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 05 Apr 2017 12:30:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1606 Lines: 53 On 04/04, bsegall@google.com wrote: > > v2: slight clarification in comments, put the conditional around the > whole wakeup area Acked-by: Oleg Nesterov 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 >