Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp440258iog; Mon, 13 Jun 2022 06:04:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF1sW62YAS9mOC2L3Q+dc5rBRRh38C/toTA5Lzi+ldpJx/NOzANdzxBdfSRWQIWFMGZguK X-Received: by 2002:a05:6402:34c8:b0:42f:b59e:b98c with SMTP id w8-20020a05640234c800b0042fb59eb98cmr53609569edc.275.1655125443032; Mon, 13 Jun 2022 06:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125443; cv=none; d=google.com; s=arc-20160816; b=Twz3F83HRalWzNfV5B9N249HQHXNkIwrTrADnZUCjmY+FRTn8+GGZWYgSzfAuLHO1K KUxJGVlmc5xbeYXUIn3mNffr5lyYt0K6O3hm4vBfdVft3Wrl2Tfcm0xwVSMDtfe52ao4 Sgh2Ar9/Ut3aWWIN/s1t365e4Y+A9FCABTxHY5I64PfF8bXoi3OmU8nbw1+W4Tnoaznd oBo0ZtCwyZelVCLp9uJDCiI64dKzCazQdNx2VhuqCkgJ245OD6/PqkiQ7oBBmeYms+97 GkhGCoe3P3apwKK9Wcg1bZMSTnzXsNNkPH51AFoDGphkHKakPJCXx761H2Iu35pehL4r B8Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pqSH5QAj4NZgV063fdV4yhQx67O9RcidkPHVVnrovKU=; b=E9534CpHC5yexnaV2K6D0mQk0ohrG/SHLpfVmR0yvrK2WYCS41z/nNX+03VcU22d36 n9YR2UHLgfJt5LhmYdpN4yB4T0+j5FSfqSqaEKWpIE+vm0APytSEsFJXUqNXre3CPvJL alduL7zi6cThrHRhqU9eESqQ9Dctf7F3Po7RVD4L1muaRgwXb6zFuNx78Yer42iCnWyq +sWWrCIPxUUyUNKwmpJFV6I2qiacJ/OQ/9qb8+lVfeNIV3AA8amIbej/srw5KCOnuqXG gwSxfasobSIvjUY7crt90459uEtxp4Lge+CR1qKK161VM7WIeJxRFryEw047vNlMxD/0 pYgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0YWipDs7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp21-20020a170906c15500b00711d54647bdsi8639222ejc.479.2022.06.13.06.03.36; Mon, 13 Jun 2022 06:04:03 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0YWipDs7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346144AbiFMKw5 (ORCPT + 99 others); Mon, 13 Jun 2022 06:52:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348762AbiFMKtf (ORCPT ); Mon, 13 Jun 2022 06:49:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98AAC2E692; Mon, 13 Jun 2022 03:27:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2F10FB80E94; Mon, 13 Jun 2022 10:27:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88246C34114; Mon, 13 Jun 2022 10:27:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116028; bh=+wk2EABwxlb5J2SZ0+gM5lgp+xcxklX2wYWqEH/OWII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0YWipDs7Skjz/5u8JV1y3Xhto6FwlTfqrFvjCeBnKgibmAqn3dZ/qWUBlwP6zPTzX mqP3m8H+X9alvhqo4pCmWp9eAZ/2OfxwI4SfkUuyJ0ZFdDn2qB93ap4cB3Ya3UqS9P jINeTU8QGJbN9UbWsKREq5dYIY0g7Am1iVLkXV9k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Kees Cook , Oleg Nesterov , "Eric W. Biederman" Subject: [PATCH 5.4 009/411] ptrace: Reimplement PTRACE_KILL by always sending SIGKILL Date: Mon, 13 Jun 2022 12:04:42 +0200 Message-Id: <20220613094928.775306086@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric W. Biederman commit 6a2d90ba027adba528509ffa27097cffd3879257 upstream. 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 Tested-by: Kees Cook Reviewed-by: Oleg Nesterov Link: https://lkml.kernel.org/r/20220505182645.497868-7-ebiederm@xmission.com Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/step.c | 3 +-- kernel/ptrace.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) --- a/arch/x86/kernel/step.c +++ b/arch/x86/kernel/step.c @@ -175,8 +175,7 @@ void set_task_blockstep(struct task_stru * * 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(); --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -1219,9 +1219,8 @@ int ptrace_request(struct task_struct *c 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: