From mboxrd@z Thu Jan 1 00:00:00 1970 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 25E28C88CB2 for ; Tue, 13 Jun 2023 00:14:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 472558E002A; Mon, 12 Jun 2023 20:12:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ACCF8E0003; Mon, 12 Jun 2023 20:12:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EDB18E002B; Mon, 12 Jun 2023 20:12:49 -0400 (EDT) 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 E6F9A8E002A for ; Mon, 12 Jun 2023 20:12:48 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C0944AF5E9 for ; Tue, 13 Jun 2023 00:12:48 +0000 (UTC) X-FDA: 80895798816.09.FBBFD3F Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf01.hostedemail.com (Postfix) with ESMTP id A600F4000B for ; Tue, 13 Jun 2023 00:12:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bYyJxVFf; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf01.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 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=1686615166; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ID5oQBvY8UKE1ZCeO9J0p0kT0pVp+VavLYCmip95cII=; b=aBxUuPfgorWDs1SJih/nKMUHgmZAAvy9mHYlma/laYMag4Y17gcOZV823qVxl712/GmOto YVEhYEBLhv+giof06XrUWvJALb5lcAIELD/1PT7xQgbZOuiNsc1Yn+ihN9TjLnhvHe0Jod +hhYpe2agAZ6aVOf82D+8hLla/0QRIQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bYyJxVFf; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf01.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686615166; a=rsa-sha256; cv=none; b=uYvvlolWR1t5QTCaIL5Ec6LpLZH3qxdSVK+jmSKseM+aj7YmcBmj2uw9vs1oIbOrjFBmPq mUvRzw3evn3IFVepDKtduk3p9OvrNWL8NyF5XAV36mCICrn1A2wbVTZnpqpxNoXYVBGP1w 2wG9fCEKOHF4Vcvs1WYjTfkOYpsFDyQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686615166; x=1718151166; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MIQ1pWvE/RoBE8pKawMdEBQM6Q57ao+KDpsn7QGopL8=; b=bYyJxVFfFBKkMXtqdYa4yEor8ICTpAIdiTx+e+lM4k8eduEx1SRGmeit +HLY4DuVxp4DC3hnPMvBpknup1vvrHSs2TQhMiyWGkDBUsS1pIhmbSfvp pdItyl6QDx5Hnhs9d6RypU+zonDZpDGNU85/CMyxY/NOhLy8Hu8zeu3v4 6qH0HQOQVIfsL5HslHS5TRMDnPfNIfeyFZx13uNuYwQlZBOtH4EOhtIgs lG/DEsvcgxwfwRRHtuQpe7L2kjjWQPl6LZfcLY/cfMHmG8KkXw2Ui1TtM /XBrpFLL7lz/2WqkpUusd7ekmMlG82+RSy1nXMg6vCA//WV6k4e7XWHN3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="361557671" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="361557671" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="835671189" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="835671189" Received: from almeisch-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.amr.corp.intel.com) ([10.209.42.242]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:43 -0700 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, szabolcs.nagy@arm.com, torvalds@linux-foundation.org, broonie@kernel.org Cc: rick.p.edgecombe@intel.com, Pengfei Xu Subject: [PATCH v9 42/42] x86/shstk: Add ARCH_SHSTK_STATUS Date: Mon, 12 Jun 2023 17:11:08 -0700 Message-Id: <20230613001108.3040476-43-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> References: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A600F4000B X-Stat-Signature: gre8xrti1a6ypbfxxonsez95dqzx1x4j X-Rspam-User: X-HE-Tag: 1686615166-712541 X-HE-Meta: U2FsdGVkX18bjQU4N2j4BPrcmWBYiHb+cvsm5h0xb7H4j2YjXgqMqyYv0kjWd2oTkG8M6rn6Fm6rIvlY3zIOIgOKtpNwr+4hhHJ0TSS6dYujMwlOWxRmhTfhZfUOxe3MHYwAQ36KlgrqROHBSUaL93SHnhCsLOs2yO/9TUP4Slxp2ogQUgSGJuDHOvZq+PhzuQvvPDPsm5JMPAp9L4WOSuTxD+KDyt96wdDQ20Ul+Po71bi8dIU7NEcBWTmIlaz+2qSiOTgCXjTND9XM9+swihMJFU6VfeiD+X/6qJeS9LUZKgJiDmuh72PD2CrYD45leAdm98KydTtIewhgkBzRzAhOmjI6RTZhsJZYzyVXY57jhgFfrhXkS6AWtBCa22crhJkfnkeAve2Qh7hWNR9h0KYJqn8zmkMCaizQDdivDEByT9LJhl/dFf8MWVNJBBKiTnU7RzqrhH1uvA4Dt38NnDRUUk1Vd+TtyZ7231vs4rYmgC285iZmhSRNJuezrEFgbUHbx95tFR0/D8XET23ymt/AcHN+XA2LfKzgiJoK6NHVDiJ0ILimByW6sa9e6MoazjW8LgLgWY+pUwV6X0lyIjAzMO1Capcf9VPQbtXnfStTuGkOnquk12Mq+ZNyPMxz4QuyAaCamYFNZN7wjfw2xkKVyZpp/nvaHNfTbr2v2/H87rcT16n7VPqHn4yS1T+7t6ggCOmcrawSwa5ZbMyYxv/ExXwj6Hq9GSbOKRXl4VA4wGSWzHkLQUdoIx1zk971MT92QadwqGfy/LBr5Fre5UhDJ6Kg1MKCxB1JCaXQYMac+tkIigf4FpT/lAI1mBsj+GqURX6ndfI8Vl4btCuub9pSZtRwB5W2SV8QsW4Jtsi2YnucqqojpBLPGxU3ZJD1igq385kcbXa/zbUMFm2R1ccgYO5tEH9BnL8M9p77qPj3c36FI86o2AEtQU1ILaPUqEBbuH/5+QGYzme6yaV xJTFuGEz jOjsb9XtuyxlEKzGJudHDtgmD1WNRLFiEZAMxZGAvBviRwyKjT7kfLKyhIj3gRCv7/SWgwSkAX28GkCYF5zf1oyOv5g8XMexXN0YvdqNi2Op9l/K6Dt18CYdxw1Rou4vf7OVtXLv7h9TJeeAbAUXjf7ShbjOIhbBgxVj4YSs6olN3LsVrjKPrvgCiIsCpCayJr2zrrvrgUbGrx0zTRYgQdLAyd20LuNegtnwkr8gDaDbT5UCYG5xzpi11VPl2C7vxyU/b3MaP7CSk1Pmv28PNnblI2wPVIPiLcqObtdvpGnuSFkqDJ2udd+XlntoeIQ35XBCr/seh6qGn/uVzmjTu9fkYFeMahjGgX634vfVywr+NMD8UO/xwpCHq/JVgQzMrLOuaa/8XeWmhAK4oIBJQvojwcv3akXHz97zT6K/yH+OtutI= 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. Suggested-by: Mike Rapoport Signed-off-by: Rick Edgecombe 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 --- 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 f3553cc8c758..60260e809baf 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 ecb23a8ca47d..42fee8959df7 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 3189c4a96468..384e2cc6ac19 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 e6db21c470aa..33b268747bb7 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 d43b7a9c57ce..b26810c7cd1c 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; -- 2.34.1