From patchwork Sat Feb 18 21:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13145680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E75FBC64EC4 for ; Sat, 18 Feb 2023 21:17:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DDBF280024; Sat, 18 Feb 2023 16:16:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19C77280029; Sat, 18 Feb 2023 16:16:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD194280027; Sat, 18 Feb 2023 16:16:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BF265280024 for ; Sat, 18 Feb 2023 16:16:34 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 94FDFAAD6E for ; Sat, 18 Feb 2023 21:16:34 +0000 (UTC) X-FDA: 80481671508.02.38787F9 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf25.hostedemail.com (Postfix) with ESMTP id AC639A0006 for ; Sat, 18 Feb 2023 21:16:32 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="SLNQ54+/"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676754992; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=XB7GgEgn63ZLeSXiVo8rMaq5mTEIs0hdTlnI+zYN+qg=; b=vv986g+t4EoTpqLHtktFSsiBrFBiouEH6WwM6xKFf72cp7Rofan3eKcDKC2zwvBlHHHB+F FwIOd9qG8KlYTxqQSnbhUrv1sCBdOCRJzBVgAU+rUOjXdC5N1TxvjO9wValoLDy/NrzYkp G+7bYRcMTceco9TcCnyb1HabUuQZ7lM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="SLNQ54+/"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676754992; a=rsa-sha256; cv=none; b=hLpadRUS3AmzYnt5A0BY/kONQO21Y6Pivd2NXIPKwUfO/R/DAomEMMcZF4zMcC6Kj6lfm1 aCbsPoYLuu+foVQxNgu9G7D2ZNW31efTrpICBvdiiPEWE9xQUyQY9cJysHUpCxuPaOzJeq WtLDYKqIg9smQvamZyYGL4MeD96hsfw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676754992; x=1708290992; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ubqwcNNiyY5+cprOn2ju85ofUOiPXcRDQntgWmd5we0=; b=SLNQ54+/H3wCqInKLKtjnfnqxr2QEQWcuHpwGTVGS4CZ3hTmGwqG1Htn 2KIEHyCaI1R+ThakLQKcyB6AEngNe7CpLq75Lfo48cBuK9CKjt65PEERS 0mMkEYFojq45ArwXH/teBRecVjKXhAyU9OKS1Vguj6ohT7RQJov08MJAs JspwWQk3yZNNRtpEaxIA5ehtokJoDKqlDV0BDLbtW6dnvM/amxIonQ9fP EQ//xxOF3HwdNTTtnIblqO68oJfNPkWaDaFUF+lpp/sKB6a2A1q+vbbpO x4+xQsNmLGD49IaCJsLAnhtXyv4SGk+4WSCAIWhvykiXTludOuKYgPW0q A==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427983" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427983" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:30 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="664241768" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="664241768" Received: from adityava-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.80.223]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:30 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH v6 41/41] x86/shstk: Add ARCH_SHSTK_STATUS Date: Sat, 18 Feb 2023 13:14:33 -0800 Message-Id: <20230218211433.26859-42-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230218211433.26859-1-rick.p.edgecombe@intel.com> References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: AC639A0006 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 6d9exkb45z8jmhfmby7r7k6g4wzke1jb X-HE-Tag: 1676754992-369820 X-HE-Meta: U2FsdGVkX1+Qcvhl6m6dAbZ0Ds2ujc94xOxzoSDTwY1a1+jQ6HYXvx19uoW0RYYSWQmubQidiLu3pBW7NjschpHRNNwqrECPNnzHRGFfz0o9QYu61hYrIIPojHxGf7UVwdKGb0vkN50ZPyNH9mJUOndn8Jk3fV04uY0xIeXMQtek3sStblCOTIKNbwMQ+LH3cgF2SpfvEhBRRnv6AFxjK2WezBD9jju+y4GbNcpFL0AdC+o9gMKb0bg89s2qAKBRBik/8NaoPRdtoshmbAPcvvD+UyHSaiibE2cAU4tEvwhpW/BizRvEhcyw5zf2RdixXHDZfqk99zMOgIm9uGEXiWohaRiZTC7xq3vQANyPuVTL34ZSVJiO7SfBGN2YFb4rXiRqDXnDhra56YDzb6C3pyUOftNw4F99XlLmnU5tFB1fMupt9fpU6Tgc98vZcHASYYyFlLlaVJsiyHlWNNJ0ICOyzH/+D7NVSP6lIy0mAtdb0NeCYUxabCiBC66n67m4XRszttoP2Zts/kITuWfqXb2CArzZiq4KtF1iwsmTa5F4ISWK2kUF1XwYTVqDMeTJ+P+/u7cCc3qW6HnbJX1To6zLJlnqpCdPYxDFECC20+u2wuNrPImYb40gIk3bwvS4+zNltyaJT/AECJ+wX9hXHDx1gQHgT9WSzCEvEhRmqIXHMi97vURtn4AYL3J9zRhg4aGIt0zIjUgCukN8yaaS7EjVz3Mn9hOWWGFob5rcA8a+sZ5LefUaOMkftdYjMsvAa/xPg/YRHsWpe6UqfOACoeHFDhZkyVva1jXLIws4mq0jEosZWWbXhLEMP/HZhCvghzVrdyi7fqDBjGw8oCePIslGA9yfGnTidsVMXpF1554q6gXlEuj1CHrJbIGpkatuMgdQbIvFMl/tId4YE8GKY4OziL5tKUWJ8zfgSQi6abiL7IZJQkqgr0ugfhSuToeN0fBtWL9YlFjpX9AoZTu lniqPXle jOFLPa+fasO4UZWnNpl8eZA79egM0HXElIYdgpAA9p2sWuqa3aYNhNcsWqzcYXcOsJ5Auj+wJpQCiqn1lQKMjnSXCaDtmUUUjkobTLsmYPsKzDu3DqOmeH7PBstnnnkagMnzFuE/5UKvecV0debx8PGt1Mf6E4qxHstfqR0B/gSjw3v4eoKqkiU33HLfh3e1vmBmZmEUR8htPuqCkCNWBvU4wrsTNWFiIdwBU3llNPCjypHlzqro+1JgABJFH55TU/IE/mEa2Y2GvtLnDgoG5GRfN1N2noZTsZhq2JOQrmp5pV/x/JEZNGB30aZJ7Jihk36GHiEf7XRxkOtd+5Ki1CjMVBVuXgWiKkiYPp8DXO8d207uhBDbSGuGu7Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Tested-by: Pengfei Xu Reviewed-by: Kees Cook Suggested-by: Mike Rapoport Signed-off-by: Rick Edgecombe --- v5: - Fix typo in commit log v4: - New patch --- 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 e8ed5fc0f7ae..7f4af798794e 100644 --- a/Documentation/x86/shstk.rst +++ b/Documentation/x86/shstk.rst @@ -77,6 +77,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:: @@ -84,6 +89,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 acee68d30a07..be9267897211 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); int 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 200efbbe5809..1b85bc876c2d 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 d368854fa9c4..dde43caf196e 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 3197ff824809..4069d5bbbe8c 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -444,8 +444,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;