From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 051E0C433F5 for ; Wed, 27 Apr 2022 13:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236244AbiD0Npb (ORCPT ); Wed, 27 Apr 2022 09:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236168AbiD0Np2 (ORCPT ); Wed, 27 Apr 2022 09:45:28 -0400 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBC531D838E; Wed, 27 Apr 2022 06:42:17 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:37046) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1njhvq-002NOG-FU; Wed, 27 Apr 2022 07:42:14 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:35838 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1njhvp-00APEt-7m; Wed, 27 Apr 2022 07:42:13 -0600 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, Oleg Nesterov , mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bigeasy@linutronix.de, Will Deacon , tj@kernel.org, linux-pm@vger.kernel.org, Peter Zijlstra , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Chris Zankel , Max Filippov , inux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn References: <878rrrh32q.fsf_-_@email.froward.int.ebiederm.org> <20220426225211.308418-7-ebiederm@xmission.com> Date: Wed, 27 Apr 2022 08:42:05 -0500 In-Reply-To: <20220426225211.308418-7-ebiederm@xmission.com> (Eric W. Biederman's message of "Tue, 26 Apr 2022 17:52:09 -0500") Message-ID: <87a6c6bq36.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1njhvp-00APEt-7m;;;mid=<87a6c6bq36.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX18mYiaAM1BjTu0hbTUozvmNmWWYJsioo9I= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH 7/9] ptrace: Simplify the wait_task_inactive call in ptrace_check_attach X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Eric W. Biederman" writes: > Asking wait_task_inactive to verify that tsk->__state == __TASK_TRACED > was needed to detect the when ptrace_stop would decide not to stop > after calling "set_special_state(TASK_TRACED)". With the recent > cleanups ptrace_stop will always stop after calling set_special_state. > > Take advatnage of this by no longer asking wait_task_inactive to > verify the state. If a bug is hit and wait_task_inactive does not > succeed warn and return -ESRCH. As Oleg noticed upthread there are more reasons than simply !current->ptrace for wait_task_inactive to fail. In particular a fatal signal can be received any time before JOBCTL_DELAY_SIGKILL. So this change is not safe. I will respin this one. Eric > Signed-off-by: "Eric W. Biederman" > --- > kernel/ptrace.c | 14 +++----------- > 1 file changed, 3 insertions(+), 11 deletions(-) > > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > index 16d1a84a2cae..0634da7ac685 100644 > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -265,17 +265,9 @@ static int ptrace_check_attach(struct task_struct *child, bool ignore_state) > } > read_unlock(&tasklist_lock); > > - if (!ret && !ignore_state) { > - if (!wait_task_inactive(child, __TASK_TRACED)) { > - /* > - * This can only happen if may_ptrace_stop() fails and > - * ptrace_stop() changes ->state back to TASK_RUNNING, > - * so we should not worry about leaking __TASK_TRACED. > - */ > - WARN_ON(READ_ONCE(child->__state) == __TASK_TRACED); > - ret = -ESRCH; > - } > - } > + if (!ret && !ignore_state && > + WARN_ON_ONCE(!wait_task_inactive(child, 0))) > + ret = -ESRCH; > > return ret; > } Eric From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out02.mta.xmission.com ([166.70.13.232]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1njhvw-001dEd-0I for linux-um@lists.infradead.org; Wed, 27 Apr 2022 13:42:21 +0000 From: "Eric W. Biederman" References: <878rrrh32q.fsf_-_@email.froward.int.ebiederm.org> <20220426225211.308418-7-ebiederm@xmission.com> Date: Wed, 27 Apr 2022 08:42:05 -0500 In-Reply-To: <20220426225211.308418-7-ebiederm@xmission.com> (Eric W. Biederman's message of "Tue, 26 Apr 2022 17:52:09 -0500") Message-ID: <87a6c6bq36.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Subject: Re: [PATCH 7/9] ptrace: Simplify the wait_task_inactive call in ptrace_check_attach List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org To: linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, Oleg Nesterov , mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bigeasy@linutronix.de, Will Deacon , tj@kernel.org, linux-pm@vger.kernel.org, Peter Zijlstra , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Chris Zankel , Max Filippov , inux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn "Eric W. Biederman" writes: > Asking wait_task_inactive to verify that tsk->__state == __TASK_TRACED > was needed to detect the when ptrace_stop would decide not to stop > after calling "set_special_state(TASK_TRACED)". With the recent > cleanups ptrace_stop will always stop after calling set_special_state. > > Take advatnage of this by no longer asking wait_task_inactive to > verify the state. If a bug is hit and wait_task_inactive does not > succeed warn and return -ESRCH. As Oleg noticed upthread there are more reasons than simply !current->ptrace for wait_task_inactive to fail. In particular a fatal signal can be received any time before JOBCTL_DELAY_SIGKILL. So this change is not safe. I will respin this one. Eric > Signed-off-by: "Eric W. Biederman" > --- > kernel/ptrace.c | 14 +++----------- > 1 file changed, 3 insertions(+), 11 deletions(-) > > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > index 16d1a84a2cae..0634da7ac685 100644 > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -265,17 +265,9 @@ static int ptrace_check_attach(struct task_struct *child, bool ignore_state) > } > read_unlock(&tasklist_lock); > > - if (!ret && !ignore_state) { > - if (!wait_task_inactive(child, __TASK_TRACED)) { > - /* > - * This can only happen if may_ptrace_stop() fails and > - * ptrace_stop() changes ->state back to TASK_RUNNING, > - * so we should not worry about leaking __TASK_TRACED. > - */ > - WARN_ON(READ_ONCE(child->__state) == __TASK_TRACED); > - ret = -ESRCH; > - } > - } > + if (!ret && !ignore_state && > + WARN_ON_ONCE(!wait_task_inactive(child, 0))) > + ret = -ESRCH; > > return ret; > } Eric _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um