From patchwork Mon Mar 20 16:39:20 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: 72280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1321371wrt; Mon, 20 Mar 2023 09:52:16 -0700 (PDT) X-Google-Smtp-Source: AK7set+NZ7S616j9fMFl+PdBChs47B34YI/uCR3wCJbQZ+fL+p9td/IItg0UTNtctkyB5n296tqb X-Received: by 2002:a05:6a20:bc83:b0:d9:a792:8e3d with SMTP id fx3-20020a056a20bc8300b000d9a7928e3dmr3553042pzb.30.1679331136287; Mon, 20 Mar 2023 09:52:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679331136; cv=none; d=google.com; s=arc-20160816; b=0zgfq66loQEjH7mKFcjRSDFUthXd2tSKP8pPkbGucEq1ClVdk/VDrtaw45chMJlIPY Lsu1Z7neEpwG4/K7DqMixRai04tObO42Qyj9GADWtZNxYxOTvKb6+gVjHjmd2gXW93Ja o5NmjuWuF0hp1hS8xbaOBRVxNpPXoy6hZKOIQzbZ4mO5m8V9kIcHyUl5fzoUdknSrNAu iqHDbVpwatiHCMaKJx0PV8bWH+dCyXlFwGBLC/T6uTWXrGwe2Oukz4+r75KL8Emyi0x1 j0AOmZsLSPGeoymnxgzLgD9RCSzopzAIPk78v3/N0s4Cm0Nna7Dvk5KuXe2MpNSFWntu SdOw== 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=YygbK75BVytnk/8a72lGD7fbAvFcWkLzTJST89VJVIs=; b=VH5yPSsMNeIquc8SaJR5q6f7ODwwjzd5DdslmzeJ5ZfhNJBGwJTyIQfBGO8bnsXaSi 2YgPKX2qkx29Svy/qi6K6/GdZCdyPHwVtC4CSjkGhUDxWo8VREEIqJQQechjLnztl9hT JTeeCp4tTTGSEWCT47H+/kfRo8gc38/EQI9+TvYRA7+0sjlvApbCMZVb1FMHWd6/SPjM /gDSC9rdE8VfCjRmT8LjbI7YVYGDXqq6p47q3XG1dRO7Xwz28nak3N7vhVkagDYcRWiH Wc4wNZCXJIrvJiU64Bc2Pe5YEQHnH7p+Ua8cJ3IvclZ5fOxOG/wXm8vGJj5cSss0HBPP kzYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=xrwuYHyQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bCog86AK; 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-20020a63050c000000b004fbba866a59si11179434pgf.503.2023.03.20.09.51.42; Mon, 20 Mar 2023 09:52:16 -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=xrwuYHyQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=bCog86AK; 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 S231902AbjCTQqH (ORCPT + 99 others); Mon, 20 Mar 2023 12:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232256AbjCTQom (ORCPT ); Mon, 20 Mar 2023 12:44:42 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E9FB1C7EF; Mon, 20 Mar 2023 09:39:25 -0700 (PDT) Date: Mon, 20 Mar 2023 16:39:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1679330360; 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=YygbK75BVytnk/8a72lGD7fbAvFcWkLzTJST89VJVIs=; b=xrwuYHyQooHoOB6dq7qoNlWstwJ0XUztWyVvpi0ZQF5lBYzoJ6gxD70xmDI9jBEJTmt6gD areZ7ZWcoOfyfVOr0YjMx+bewXwkTVX3/SPJootoMUysW9PJNo7aiNQnkifDQ6pMtKqRio X9BfqS+JvY2LJHJjpdxAQr1sGox0pTkret3ttUJvaz0F43ES37q1WWOyXEDk/B/di7zlJO Fr4Ur8sZ3CM4WegaVaK+n+NbPwGjq/9+9YiW/qbM9smtJdiV6s3y0GiLFArIxDz05a+P8J 5Srb+gD3NJPXMEMT8QaABOcSo/+Rbf1b1lulsLfNq776opHbpAwCFUizcmH8VQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1679330360; 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=YygbK75BVytnk/8a72lGD7fbAvFcWkLzTJST89VJVIs=; b=bCog86AKN36ukVSf/jYBrH0DLINYeJVz19nwqGTUCB5eYXTlNEj6cNkmgKy5JS34/iaijj MCFhlVj1lBE7odCA== 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: <167933036006.5837.12482460743120391374.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760906325338489163?= X-GMAIL-MSGID: =?utf-8?q?1760906325338489163?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: b642e9e5f0dc797f543b431d4ba910a3da72a074 Gitweb: https://git.kernel.org/tip/b642e9e5f0dc797f543b431d4ba910a3da72a074 Author: Rick Edgecombe AuthorDate: Sat, 18 Mar 2023 17:15:35 -07:00 Committer: Dave Hansen CommitterDate: Mon, 20 Mar 2023 09:01:13 -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/20230319001535.23210-41-rick.p.edgecombe%40intel.com --- Documentation/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/x86/shstk.rst b/Documentation/x86/shstk.rst index f3553cc..60260e8 100644 --- a/Documentation/x86/shstk.rst +++ b/Documentation/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 200efbb..1b85bc8 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -26,6 +26,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 69d4cca..3124193 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -836,6 +836,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 ad336ab..1f767c5 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -452,8 +452,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;