Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3856294iob; Sat, 7 May 2022 18:02:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG5hO6q3y5YTrVbpmNcgw0jb8nMO32o6ajIxLeY+BM3/Hh4fMlic8fETiNrHgyZ/SnkG7B X-Received: by 2002:a17:90a:d3d1:b0:1bb:fdc5:182 with SMTP id d17-20020a17090ad3d100b001bbfdc50182mr19750203pjw.206.1651971773735; Sat, 07 May 2022 18:02:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651971773; cv=none; d=google.com; s=arc-20160816; b=W469VZaAcO5X3ddKrpsF1aKXaHPz0KZMkitCFHrhlxnoLfPK7/LvEmga6V9RD7z4fm 7tWkByMXkX/CQylwx1n6cURjgbjzboS9rse+vUxxkXdl1JYZbRpyTBjuYr8Fn28ou5NN jvyFdMKhUr5AGa/UY0HR4xwwDF5PBl9kmb4bp+IZN9sDER3ee9J6iF4WTUnjG449gjvH nyw2J8SvCu6hQ8l6YykIrjyBn0Icf9KBgDw34SGRNc3oB4JssK8Lmvz3AvyxLX41PlwS i2Z4Xff9PTB0PN1c75OEQunY+lro0+IdxtIPFnPojbB3md0L0RyF3//f/w38880cDWMY fnNA== 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=Yhp6692D5xzD1zEhBtIPBI/lKJPo9F9XNhECKlwznnvAKsVzFdl7sy44egtxor7WQk mZB9TiS0MUF4g6jNjFAzV/auNnvQLYAsRjRUmsI1vfPXyT4Cyy3v6c/NdvDlFSBjc7wD /jQBMb90aFwvpdh1Lhq39qrmgezwRPFJ2mYOwAP/CctGMiz41JCI6cYsjP09qAxVfUDl jg19sA8as3x2MNZypT0730N/BTLDJPELxLIh2mr1CHtplOzjQ+02kA7kYumxzExDYyTd N/tChJoiOLovH6qo++WXrsmIpXbkskZd5m1/wJ1EKcHekPz4RlcB7affU1qw0yzrIzeF esiQ== 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 c10-20020a63724a000000b003ab158e5a5esi8889950pgn.121.2022.05.07.18.02.40; Sat, 07 May 2022 18:02:53 -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 S1384396AbiEESiL (ORCPT + 99 others); Thu, 5 May 2022 14:38:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384368AbiEEShG (ORCPT ); Thu, 5 May 2022 14:37:06 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 468285E764; Thu, 5 May 2022 11:27:34 -0700 (PDT) Received: from in01.mta.xmission.com ([166.70.13.51]:59586) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nmgCL-00GUvI-6a; Thu, 05 May 2022 12:27:33 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:37118 helo=localhost.localdomain) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nmgCK-002BtP-2F; Thu, 05 May 2022 12:27:32 -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: Thu, 5 May 2022 13:26:40 -0500 Message-Id: <20220505182645.497868-7-ebiederm@xmission.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87a6bv6dl6.fsf_-_@email.froward.int.ebiederm.org> References: <87a6bv6dl6.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-XM-SPF: eid=1nmgCK-002BtP-2F;;;mid=<20220505182645.497868-7-ebiederm@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX19NRZcRcR23auMiCzqsQtGurcA8snLDuqU= 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-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=38 X-Spam-Combo: ***;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 490 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 11 (2.2%), b_tie_ro: 10 (1.9%), parse: 1.08 (0.2%), extract_message_metadata: 15 (3.1%), get_uri_detail_list: 1.85 (0.4%), tests_pri_-1000: 20 (4.1%), tests_pri_-950: 1.21 (0.2%), tests_pri_-900: 1.01 (0.2%), tests_pri_-90: 120 (24.5%), check_bayes: 118 (24.1%), b_tokenize: 9 (1.8%), b_tok_get_all: 9 (1.8%), b_comp_prob: 2.8 (0.6%), b_tok_touch_all: 93 (19.1%), b_finish: 0.89 (0.2%), tests_pri_0: 310 (63.2%), check_dkim_signature: 0.74 (0.2%), check_dkim_adsp: 3.1 (0.6%), poll_dns_idle: 1.17 (0.2%), tests_pri_10: 1.78 (0.4%), tests_pri_500: 6 (1.2%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH v4 07/12] 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 in01.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