From patchwork Wed Jul 19 22:47:25 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: 122902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2770294vqt; Wed, 19 Jul 2023 16:24:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGdtAN8uOTELsQEu3e8Dzz/5OzxZayktSd+NDKJKKteUTXBglGC1aQASLkO5Q5nmCwijHDS X-Received: by 2002:a05:6a21:789d:b0:12f:21fe:f156 with SMTP id bf29-20020a056a21789d00b0012f21fef156mr4526727pzc.0.1689809086061; Wed, 19 Jul 2023 16:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689809086; cv=none; d=google.com; s=arc-20160816; b=omwAj39Gv0Wb2UEwlNCJ2JLPtRsehCD2Xyyzjq9Ovz2ffpIODgDpByX1TuzoBWg6PV pKzkqKWzc4JPj6XVBJNDss0vO/zQk+6kstzEPMDS+HaaXicWb3YzPDSPtUchHbGpTus7 d2TE7LJC9i1d6MQLSh6sfj73zhSkm/pXqYN+oypOSqn7EEwfYrALdvRki5f+93H5tb0T fqy0LrZaza7u+QuK9n5yO2Wa+TFL3qzsrvjNjB/24wq+p8VK74ak++xRQ/q5mKj4MJyn WF++1GpAikVZ45fCH+MQnxliIG256V994+FoJGdQXu69+UP0YynqX4CNLBJygJgAWzWC vVIA== 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=giUarVDnv1Z4cvepgxL2Be4qlcKqGuVFS1qBPnFcdD0=; fh=vA+UuvN2odZTeRBwRYj/YXZa41onyRjaIDsQC/bfR+A=; b=mx7FSD44nsraCnwkQVaruZZdtqOHTkrfcB9e+OTEVaxp5iDZzx2qoeW5Q6BN7bLZ2X FdJCmWsbqeQO1hX1cYW1mf9ig6x4URjaxfaizAjO8M99a81L7B+yGA1yQOKTE9+ySOFT zMuvaoxzV/194ku9sUmOHYJsTMsv9R/jSVhUEblN041NOBtTQiUGsukh6OXrvLeBRDGg cYXN5bZWJkHSkwXIo2j3PYvGDB2iRV9wolXeb3nH9XRv4BgZ71fRXnNwtoC9VptCAoOF fbMOeH8S/wlyRnlebsTygC6IUFz9YTYTwDGSBWpuYHFh8AE0vzjjTvh02/DtYNvah0rP /gFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=RPBUsSap; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3DCUWoIO; 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 f1-20020a170902ce8100b001b8698149f2si4577616plg.588.2023.07.19.16.24.33; Wed, 19 Jul 2023 16:24:46 -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=RPBUsSap; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=3DCUWoIO; 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 S230046AbjGSWrd (ORCPT + 99 others); Wed, 19 Jul 2023 18:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjGSWr3 (ORCPT ); Wed, 19 Jul 2023 18:47:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462FB1FF1; Wed, 19 Jul 2023 15:47:28 -0700 (PDT) Date: Wed, 19 Jul 2023 22:47:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689806846; 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=giUarVDnv1Z4cvepgxL2Be4qlcKqGuVFS1qBPnFcdD0=; b=RPBUsSapf5QCVvtmPNOMeAy+2lILSV8GeD1+iNmDnvdiS/B7LRg2sGLH6Y3Ru9ukWpDJ6u x9ndeAEIa7DkfGiqlDFg5L+7YoqF1C0TlMw2giRiQaBsH+DOUZM5/dXCo/0Z7AKAdJZYB1 Hb3IoPOE7S7Ldc7K8U1nyYJ23UOGOqABMeD1QeOVrao+ItbKj3cp2izO6NXNqToYQi4ymJ pelNUYFNVuHJ+gFsvxBoN+ENPJKQADi3GW4is1rQzy8bIVoWjL7PVhIBAlhqZrr2REibyN JHUe1JuZiEsNqR4ZhO87HLZa5QxMeBIhD9Ei5Btc1h7ZPOEUSa+ZQ62YqfPo0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689806846; 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=giUarVDnv1Z4cvepgxL2Be4qlcKqGuVFS1qBPnFcdD0=; b=3DCUWoIODa/svnS8S9lsYBsQQHcGDGUaEh/50BVwlc6FbZbqfOiCzOnns4MgrcDXy6e+Yj HXQs2LpzbovZ0VBw== 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: <168980684564.28540.1364207622351188041.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: 1771893252206782050 X-GMAIL-MSGID: 1771893252206782050 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 0b3374b01dd47b29ca87f4523340ec142510335a Gitweb: https://git.kernel.org/tip/0b3374b01dd47b29ca87f4523340ec142510335a Author: Rick Edgecombe AuthorDate: Mon, 12 Jun 2023 17:11:08 -07:00 Committer: Rick Edgecombe CommitterDate: Tue, 11 Jul 2023 14:14:15 -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;