From patchwork Wed Aug 2 22:19:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 130201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp781685vqx; Wed, 2 Aug 2023 16:06:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEx9WE4NXu7TYCpRzMHwVfgx9Ag+0yBz+jzmwUVXMpdzKT7VQlNXYf2hdmKCSAeK8DUjzNt X-Received: by 2002:a17:903:1d0:b0:1bb:b832:4be9 with SMTP id e16-20020a17090301d000b001bbb8324be9mr17871737plh.1.1691017578051; Wed, 02 Aug 2023 16:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691017578; cv=none; d=google.com; s=arc-20160816; b=Q+Y7Ymsr+qrOGV3BaKinfMtW6tddc+/46UYPw1ZN7PXVeGgO3Hjj6NJ9XShBT7Omt/ XJwuajLWJkN3+nQsbn/zp7YVUN+ckXQxt5FwwzKJkPWRmiP4nwkHIdbM5DaatsUFkaOf IPVooapLB+oixyZTBgmlFWln0RmtSjsnl2/U+iau7zrC90QFp5K+VY9BPxvuwAzF9Fag fRlwJQLwHhKKoCpfV4NAFHCNx1LGDfMUm0nZ/xzyNKBydtMwu2ZL/mt7qcktSbfgRFhD HHOSS+H/9Y+uOipGPaf6fPmOH6OHKim/pvgiywlsGE1IiiD1juf+14mX+Z/JIzGLTfJp YR8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=fgFDSCuzuCVdQTPqITO52kmY5fHytV3PG47EEZr6ArI=; fh=vA+UuvN2odZTeRBwRYj/YXZa41onyRjaIDsQC/bfR+A=; b=y83Bn1rjkmnv4WazQ6P1z+WxKqFt/I5WfBYr/V14lFbGqVGASyJCyAPRwEzl45/PJZ Ve8dboy0W0L1xm+UJ9y9JAO8fGhVK+QNoHLhLHiGcBNh0Fv2QWOoDJkxrXghYCt01laa KDPU00Yw9hkHmhter/Vpk8SywvWb1tvJtQUdeQ/NrTBeXD/Domubj6gpdTRtV50Cf9hi Ts2O/w4eQvBbEFNkQ25U4ST6QZyfzRngSZfGWe73Uw0ojxbCRvEumRqkv/6IeXoqM/4s B3x2k2NXHGEuXVt8I5+Hr4i90v9I1xOgyJTVRCpMHWKcpiyAZb+y7L8txemuwuRUiODy FT4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3lyiurnN; dkim=neutral (no key) header.i=@linutronix.de header.b=zG+TyVjc; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a63134c000000b00563adcaab61si11421344pgt.865.2023.08.02.16.06.04; Wed, 02 Aug 2023 16:06:18 -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=@linutronix.de header.s=2020 header.b=3lyiurnN; dkim=neutral (no key) header.i=@linutronix.de header.b=zG+TyVjc; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbjHBWTl (ORCPT + 99 others); Wed, 2 Aug 2023 18:19:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231309AbjHBWTa (ORCPT ); Wed, 2 Aug 2023 18:19:30 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 525CB271C; Wed, 2 Aug 2023 15:19:27 -0700 (PDT) Date: Wed, 02 Aug 2023 22:19:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1691014765; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fgFDSCuzuCVdQTPqITO52kmY5fHytV3PG47EEZr6ArI=; b=3lyiurnNDlOqYwh45Vm1yFq3oxBhpo/rLBk97u67ZINGlgtWUpvooBObecZfZQOtubC+LA YgNNqnoO4F3ocrq6VcmMMzaOVqu2wEX5Migrdko2nJ/1bws+S7wliotUoY1dVGKzZiI5ry XTodp83GI2N6oPjg9CSysj885vfxA8Fe/a8lAyK8Ikjjz7YApz8k3ntOCVFud09XHOS4Hd DhnhqEzOVR49Gqi5/3CEZFQBcTNcp6Izf1HAssjJPnd/BFXUR1zQWZostFDTYasPmzFvxe ENkWsfjy7EJjJ+MG7SaBPTIRvmTSWlMtENoNLqX8klPgDTYt7Eo0/oSrZfvp7A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1691014765; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fgFDSCuzuCVdQTPqITO52kmY5fHytV3PG47EEZr6ArI=; b=zG+TyVjc8H5vUADTDWZ82wNfIDFS7q2otntbCWR47klL/+0cYXUwZZXC8NmSef647TP4f9 stu0t30SuGgaNHDw== From: "tip-bot2 for Rick Edgecombe" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/shstk: Add ARCH_SHSTK_STATUS Cc: Mike Rapoport , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169101476494.28540.49280058959276015.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773160448243139110 X-GMAIL-MSGID: 1773160448243139110 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 67840ad0fa14ad49a605074b12d5b0f3c3113ed1 Gitweb: https://git.kernel.org/tip/67840ad0fa14ad49a605074b12d5b0f3c3113ed1 Author: Rick Edgecombe AuthorDate: Mon, 12 Jun 2023 17:11:08 -07:00 Committer: Dave Hansen CommitterDate: Wed, 02 Aug 2023 15:01:51 -07:00 x86/shstk: Add ARCH_SHSTK_STATUS CRIU and GDB need to get the current shadow stack and WRSS enablement status. This information is already available via /proc/pid/status, but this is inconvenient for CRIU because it involves parsing the text output in an area of the code where this is difficult. Provide a status arch_prctl(), ARCH_SHSTK_STATUS for retrieving the status. Have arg2 be a userspace address, and make the new arch_prctl simply copy the features out to userspace. Suggested-by: Mike Rapoport Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230613001108.3040476-43-rick.p.edgecombe%40intel.com --- Documentation/arch/x86/shstk.rst | 6 ++++++ arch/x86/include/asm/shstk.h | 2 +- arch/x86/include/uapi/asm/prctl.h | 1 + arch/x86/kernel/process_64.c | 1 + arch/x86/kernel/shstk.c | 8 +++++++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/arch/x86/shstk.rst b/Documentation/arch/x86/shstk.rst index f3553cc..60260e8 100644 --- a/Documentation/arch/x86/shstk.rst +++ b/Documentation/arch/x86/shstk.rst @@ -79,6 +79,11 @@ arch_prctl(ARCH_SHSTK_UNLOCK, unsigned long features) Unlock features. 'features' is a mask of all features to unlock. All bits set are processed, unset bits are ignored. Only works via ptrace. +arch_prctl(ARCH_SHSTK_STATUS, unsigned long addr) + Copy the currently enabled features to the address passed in addr. The + features are described using the bits passed into the others in + 'features'. + The return values are as follows. On success, return 0. On error, errno can be:: @@ -86,6 +91,7 @@ be:: -ENOTSUPP if the feature is not supported by the hardware or kernel. -EINVAL arguments (non existing feature, etc) + -EFAULT if could not copy information back to userspace The feature's bits supported are:: diff --git a/arch/x86/include/asm/shstk.h b/arch/x86/include/asm/shstk.h index ecb23a8..42fee89 100644 --- a/arch/x86/include/asm/shstk.h +++ b/arch/x86/include/asm/shstk.h @@ -14,7 +14,7 @@ struct thread_shstk { u64 size; }; -long shstk_prctl(struct task_struct *task, int option, unsigned long features); +long shstk_prctl(struct task_struct *task, int option, unsigned long arg2); void reset_thread_features(void); unsigned long shstk_alloc_thread_stack(struct task_struct *p, unsigned long clone_flags, unsigned long stack_size); diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index 3189c4a..384e2cc 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -34,6 +34,7 @@ #define ARCH_SHSTK_DISABLE 0x5002 #define ARCH_SHSTK_LOCK 0x5003 #define ARCH_SHSTK_UNLOCK 0x5004 +#define ARCH_SHSTK_STATUS 0x5005 /* ARCH_SHSTK_ features bits */ #define ARCH_SHSTK_SHSTK (1ULL << 0) diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index e6db21c..33b2687 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -900,6 +900,7 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_SHSTK_DISABLE: case ARCH_SHSTK_LOCK: case ARCH_SHSTK_UNLOCK: + case ARCH_SHSTK_STATUS: return shstk_prctl(task, option, arg2); default: ret = -EINVAL; diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index d43b7a9..b26810c 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -482,8 +482,14 @@ SYSCALL_DEFINE3(map_shadow_stack, unsigned long, addr, unsigned long, size, unsi return alloc_shstk(addr, aligned_size, size, set_tok); } -long shstk_prctl(struct task_struct *task, int option, unsigned long features) +long shstk_prctl(struct task_struct *task, int option, unsigned long arg2) { + unsigned long features = arg2; + + if (option == ARCH_SHSTK_STATUS) { + return put_user(task->thread.features, (unsigned long __user *)arg2); + } + if (option == ARCH_SHSTK_LOCK) { task->thread.features_locked |= features; return 0;