Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2183861iof; Tue, 7 Jun 2022 22:29:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyub8xivwAVPTHO1oTL33gKAr8/e0V05kgjK1gs9toJpWKa8gPqSkKmNKokTDE/NSLW2JTd X-Received: by 2002:a05:6a00:813:b0:51c:17b2:60cf with SMTP id m19-20020a056a00081300b0051c17b260cfmr14613776pfk.70.1654666152424; Tue, 07 Jun 2022 22:29:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666152; cv=none; d=google.com; s=arc-20160816; b=sKAiJQEUvnR8rscHuFOP5VVspr/ylcvQmpK7RtX6Mi4+CnGSfvOR/rqoT15MaYanjM rakQCs4StKrjIrHQMHPyzbIWgBXlyc0mdS4bb5R4qpmAt5ddCAcrtgt2kYiXQUVoKETF rzF9GGmLwSAgTgGwHyZNHGabiVM6NRT37MLVPT3lmcpnbdpfD62z//9DqbJ6qJ9enOJJ VpqRk61uv/ZcgTmx6/JZr59e6X/yVT7VpXpw2jhhnIZ//r2VK8u74QLQo7j9HEr15zY2 8VxZOVSNIfhmC798eR8s82UGw90o1ueQ1+umTEeJy9oNBH60ay3Cih3Q+TCOozlB6mFa TVMw== 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=riBvPJ7oi2Z2ICkMEIUBddXz+LU/A03VONC6uFqqbTIxUHzwX8lzfxifI9NWmOSeso unZ1pNnP+numDJqtielxeOQurfh/SuYlh+BjbqyRn3Db7o90Zxt6e3DDtnTWn4Cs/5NC DG21xY8S3RDfE6KWGJ0UCGikicZYCnBD9qfA8gAnXWN+FZKZBWREwgkawbhxr/AnUEm5 qjx/oS1Y5Rwv3UOf/SOPSZV0z2Vh0E56mPm409t4rAE4bDx1AE1hoprMcIqTZhfSWfer DczykSzGm/d+avXKBFQkc2swVIuFY12VVdV36Z7JAVBhnNNRMLE/czT2aYNQFh1wZogG p//A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QZFV0Bes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e8-20020a17090a728800b001e2818ea430si29110221pjg.86.2022.06.07.22.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:29:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QZFV0Bes; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 522F23BCC7E; Tue, 7 Jun 2022 21:55:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345745AbiFGRTX (ORCPT + 99 others); Tue, 7 Jun 2022 13:19:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345638AbiFGRS5 (ORCPT ); Tue, 7 Jun 2022 13:18:57 -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 ECAAB104CAF; Tue, 7 Jun 2022 10:18:54 -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 3FB97B822B8; Tue, 7 Jun 2022 17:18:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D6A2C385A5; Tue, 7 Jun 2022 17:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622332; bh=+wk2EABwxlb5J2SZ0+gM5lgp+xcxklX2wYWqEH/OWII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZFV0Besf34kdH0etBUi+MK97U9eEfuZ/KWg/CGmBOPz4NgbOAreA2v4BciI5jTdg m59LfQJlGrzmfOPLuS6auuzX/KA6MOCQZaWPXL9FOTYt49HxZhiVpHGtbtgDYG/SmT T6Z8yXQRC7HtZJMPBH4rI6BHYz5oRweIAUOi6Vhg= 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.10 021/452] ptrace: Reimplement PTRACE_KILL by always sending SIGKILL Date: Tue, 7 Jun 2022 18:57:58 +0200 Message-Id: <20220607164909.173940860@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: