Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3287343iob; Sat, 7 May 2022 01:05:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7J2kwgMW2RJ82tIPWms8adnRO51R9OKi8dW9HZkK+CHBNmAfn5uom3ojn0vrER2p8k9LG X-Received: by 2002:a05:6a00:1391:b0:50d:e125:e3c with SMTP id t17-20020a056a00139100b0050de1250e3cmr7393111pfg.75.1651910740608; Sat, 07 May 2022 01:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651910740; cv=none; d=google.com; s=arc-20160816; b=LVGdmSrq1tTyEG457STO5UeVGQ1Y0+mA5T05Yd9av85FYGfLP4rwgz07WjOJvqT1OF MXwg9l6oAaqOJCdy7z6YtshNEPdsKmMYjcYYCRzoFr3hL+AZH32czK/7PAfwGCbXmzfH hOEib5QOw0Wkt7c2hSikDVrzlM+oMb0Z9wGpg9Q1UEQ7Msy3yd/PkNo9j9AqyBhFKWCL yvBGxvU8BRliG6bEqu4DbGFFg2udE/6rwO49rVElGCnzHOPgvVKKvNSPdQE4TYfp0DHr SL2rPV7ITvj9AFe9pOJPUcnpXPQTvSXmIYKDG3QEaO2RLHS2hSgAYux3MgPJ+Q2Bz/c5 OC9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from; bh=F5cP5PMawQyqyn+x36wC5ihPoma40h84GprdY51ut6U=; b=U4VwEx996bVQxA0KaiOM2YnThaiiuaNqSHdujBhKTO02Y/zNn5OxOSzD+yE4Nx0VzK t7n+am9/Yc5D2vQ2E4Zeqf2FOFntII7lSIvQL2WL9CuVPu0IZ3TCrHI8LxYIPq9aNsSE E1TaSTJnwowMNrlGXQflpsjgqNTuQQgyqoJKL+2JDhMOE83kzwQP7nWIm9zVQ4fXBs3u 0Up15a6qNfVfMpXwy9NAhnAgKKJlq81V2cZqRMRM69iM82LLjO0/P0X68/4bCfK++9de ecrxQT8D8Ki8rIvU/TYWgucWH+h7F2tHNizhLiSg1Iulvc9AXfuew6TbM+WVdW+2EEXD XldQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e12-20020a17090301cc00b0015ea8b56188si5197398plh.56.2022.05.07.01.05.26; Sat, 07 May 2022 01:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379094AbiEDWp2 (ORCPT + 99 others); Wed, 4 May 2022 18:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233395AbiEDWpX (ORCPT ); Wed, 4 May 2022 18:45:23 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89D9B532D9; Wed, 4 May 2022 15:41:41 -0700 (PDT) Received: from in02.mta.xmission.com ([166.70.13.52]:54408) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nmNgi-00EDTM-51; Wed, 04 May 2022 16:41:40 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:37004 helo=localhost.localdomain) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nmNgg-00GI0k-0N; Wed, 04 May 2022 16:41:39 -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 , linux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn , linux-ia64@vger.kernel.org, "Eric W. Biederman" , stable@vger.kernel.org, Al Viro Date: Wed, 4 May 2022 17:40:54 -0500 Message-Id: <20220504224058.476193-7-ebiederm@xmission.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87k0b0apne.fsf_-_@email.froward.int.ebiederm.org> References: <87k0b0apne.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-XM-SPF: eid=1nmNgg-00GI0k-0N;;;mid=<20220504224058.476193-7-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX1+9SzvGr3G17al133A5T0b3rkn3nFKja+0= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Virus: No X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 1486 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.9 (0.3%), b_tie_ro: 2.7 (0.2%), parse: 1.11 (0.1%), extract_message_metadata: 17 (1.1%), get_uri_detail_list: 2.3 (0.2%), tests_pri_-1000: 15 (1.0%), tests_pri_-950: 0.99 (0.1%), tests_pri_-900: 0.85 (0.1%), tests_pri_-90: 137 (9.2%), check_bayes: 135 (9.1%), b_tokenize: 7 (0.5%), b_tok_get_all: 7 (0.5%), b_comp_prob: 2.0 (0.1%), b_tok_touch_all: 115 (7.7%), b_finish: 0.78 (0.1%), tests_pri_0: 1300 (87.5%), check_dkim_signature: 0.60 (0.0%), check_dkim_adsp: 2.7 (0.2%), poll_dns_idle: 0.83 (0.1%), tests_pri_10: 1.81 (0.1%), tests_pri_500: 6 (0.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v3 07/11] ptrace: Reimplement PTRACE_KILL by always sending SIGKILL 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 The current implementation of PTRACE_KILL is buggy and has been for many years as it assumes it's target has stopped in ptrace_stop. At a quick skim it looks like this assumption has existed since ptrace support was added in linux v1.0. While PTRACE_KILL has been deprecated we can not remove it as a quick search with google code search reveals many existing programs calling it. When the ptracee is not stopped at ptrace_stop some fields would be set that are ignored except in ptrace_stop. Making the userspace visible behavior of PTRACE_KILL a noop in those case. As the usual rules are not obeyed it is not clear what the consequences are of calling PTRACE_KILL on a running process. Presumably userspace does not do this as it achieves nothing. Replace the implementation of PTRACE_KILL with a simple send_sig_info(SIGKILL) followed by a return 0. This changes the observable user space behavior only in that PTRACE_KILL on a process not stopped in ptrace_stop will also kill it. As that has always been the intent of the code this seems like a reasonable change. Cc: stable@vger.kernel.org Reported-by: Al Viro Suggested-by: Al Viro Signed-off-by: "Eric W. Biederman" --- arch/x86/kernel/step.c | 3 +-- kernel/ptrace.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c index 0f3c307b37b3..8e2b2552b5ee 100644 --- a/arch/x86/kernel/step.c +++ b/arch/x86/kernel/step.c @@ -180,8 +180,7 @@ void set_task_blockstep(struct task_struct *task, bool on) * * NOTE: this means that set/clear TIF_BLOCKSTEP is only safe if * task is current or it can't be running, otherwise we can race - * with __switch_to_xtra(). We rely on ptrace_freeze_traced() but - * PTRACE_KILL is not safe. + * with __switch_to_xtra(). We rely on ptrace_freeze_traced(). */ local_irq_disable(); debugctl = get_debugctlmsr(); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index da30dcd477a0..7105821595bc 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -1236,9 +1236,8 @@ int ptrace_request(struct task_struct *child, long request, return ptrace_resume(child, request, data); case PTRACE_KILL: - if (child->exit_state) /* already dead */ - return 0; - return ptrace_resume(child, request, SIGKILL); + send_sig_info(SIGKILL, SEND_SIG_NOINFO, child); + return 0; #ifdef CONFIG_HAVE_ARCH_TRACEHOOK case PTRACE_GETREGSET: -- 2.35.3