From patchwork Thu Jan 19 21:22:41 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: 13108779 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 CB30BC004D4 for ; Thu, 19 Jan 2023 21:23:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 725256B007B; Thu, 19 Jan 2023 16:23:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D6A66B007D; Thu, 19 Jan 2023 16:23:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B5396B007E; Thu, 19 Jan 2023 16:23:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 35FB46B007B for ; Thu, 19 Jan 2023 16:23:33 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1022E1A03B3 for ; Thu, 19 Jan 2023 21:23:33 +0000 (UTC) X-FDA: 80372825106.25.F8B348B Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf27.hostedemail.com (Postfix) with ESMTP id E4B1640007 for ; Thu, 19 Jan 2023 21:23:30 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TMJlcKO3; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 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=1674163411; 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=4jbP/vvwC2xDxOm16xmDL1x5rE+wMcxLrGHW3HbSuJY=; b=PBtvGtWRcyHLZcXnNXBGBrpooJb+MQjYmNJvBcFVyCe5ZonYZFIQ5yGHhqCkJ7I//xHv6S wGBDP+aBZPfA4Enw1s8M9rP0Lk74mUMC1JVczMQfCAduQW8JXQAfXlBDUTNFp95GQRujOw /2AH4W0DCI2/hr0to7bogJSkj8ZG+LM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TMJlcKO3; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674163411; a=rsa-sha256; cv=none; b=VMCU7HD4TLhH7uI3ATdqkZ1G1dgR4MNTLb48h96hDbKMFwcF8DT2Hj2kX70DiEwlpcicx6 v9jA8RHCzS8RN2fuKpqZSmAe80BiwQA4jPIwJ6cZ6QygfGlAmgXwtlEN06FFiMnA8q2zaK f34uE3zEGFjuti2UU9PTUIr3klo6ahk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674163411; x=1705699411; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=d2PWSkL27px2D+va1Qwpdf/EaJ+P/H11jw+dYhLJV08=; b=TMJlcKO3SdmCH4hZt9oF9u4A87BhWF4R423f3VLo46W6UaUNBruq7EgM 5rDRdYItKcHody5diviITJRQDMG2kAi7rlWGyHCptuPXvRWul1g9DKfU6 xzmNDKgw63WP2GQr72q5AeJ/7+NcilYfrzKx3dzDunB/I4Om5fSbt/tpD 3JdhbZolKOSNGRUkobTfsbXfNIOf/CyVNdsA+/z+yBX6vHbUcZQmQkT+C o5HI9ZpS70igXwv3I71ZscfefYJACXXM2CI+rL4wAZxpHZghFhUA9B7xH 1pPoQ9M/a30ahUZHIiAGufTB6s8POXGCy+7aG1LxWcVV/FsFh8YWrl0VR A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="323119221" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="323119221" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:29 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="989138996" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="989138996" Received: from hossain3-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.252.128.187]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:27 -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 Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v5 03/39] x86/cpufeatures: Add CPU feature flags for shadow stacks Date: Thu, 19 Jan 2023 13:22:41 -0800 Message-Id: <20230119212317.8324-4-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119212317.8324-1-rick.p.edgecombe@intel.com> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: E4B1640007 X-Stat-Signature: cchs13antgk44q6odfxbp6jzdoqghctp X-HE-Tag: 1674163410-274722 X-HE-Meta: U2FsdGVkX18lJOvID/L7YpQg7SKsGNqLSELSb4hGmvIFaGooeOYdA0k4LnmPMu0dmV1HM9uLrwUXjDVLheTil1CD6qCV4yS1x8ZFLtsr/azAQyBj5miTb7QwHS47RQVeZ/KpW7+t3biIxdfntGBDzfZQGTGWnIpIbiKh6lHAXcX1x03Kxnu5dlZ8fyMQX6SIO7p3rF7UUVSm2yAtU24M4VNWheKAKSUhaVxB2/9YFRHMKCOsgEMbqB5e6OmTawSwXQVXZt3YVC9fF8Le1ukPaq6ca8tUwDUMOAHYC/puSTOAFfYy5OTZEILVEtfe7mqt3HSK+O16DfHk2I5Iw5k1PIcQbd5Y4LidqcA7ANttEH179r6aZ2OU96s++/mC+HIngg4+fTPVQdmxFUooHZN3bsuMbibLq5VA8vzrTRDQEMybnqsD0cQRKr1Zyr7BKkeFhreFPYuOJ28YG20uB6AN3QoWK2pexpuX+kBfhjPk0iozTj8IF8NBSl7AiGGLCbLcZIh8Li6Ttc5Azbi15JK21z7+sIu3ocp51E60rQxHwAkIHo5jFfAlTDtZGryh5CDwu4XtxMpZT3kiZqkahrIFZloTPhB2YRupYq4WsOszHZhpuFDdR9bCwDowkCoCtOR23xNRftqPlgI3jDZi7j+ERj61ZzVtP8BznpYz+sCIi4pQRFbRxm1lRCqE8Fra3Kn8pqkowcztzzWICyz4ha4kQJ90ZZqNZzMKBrmM/auU70K8pxH7yLSwEWOoaiW0TPAnfoI/CjCD2TBeRReYBgv2Azh2KrOiBvw8zWNFZR2tIVueyDgf31FIDV3B4cNodZ2UK1qqxQWArvOhca9CrslGxHEqm/fGDm7CprjOxBtu5YB+ZirSn9ak2z+ZkJc1d8qSqT9i6pU2QyDt+ig99igTTk3BgYPourMcAEF6scQHTBcXHgxaqh7okdO6Uei4ZGUtg8gNtD/NR/QQhmVpzC0 2drIjUbR BiM7dUyiCuPFFCKeNo+Rz4pQp3xEvEDtuWObxwmoUv9FF7YsWMrYTNfpbR4fX6kxbOU4oPp9eHHeokjc605nsVr/M0Xw8GtMybXcsDzvCIxUzLIgApzqar+KfBXcqHxcLmyAmElAp3RXLw54xTy6BU92seA4y1VKCA4az+ODp82P+tXSut13uFTZqKzaQSMEUzR5BwrFtLuY5HZiBNlalH3XK7YUPvfkBku1fW9ps8Nh0mEMTB00VTDWvIh5SrEsR7L2+9/eBBIk1FIeo1EwXdmS8VWmnMQ6XosPx 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: From: Yu-cheng Yu The Control-Flow Enforcement Technology contains two related features, one of which is Shadow Stacks. Future patches will utilize this feature for shadow stack support in KVM, so add a CPU feature flags for Shadow Stacks (CPUID.(EAX=7,ECX=0):ECX[bit 7]). To protect shadow stack state from malicious modification, the registers are only accessible in supervisor mode. This implementation context-switches the registers with XSAVES. Make X86_FEATURE_SHSTK depend on XSAVES. The shadow stack feature, enumerated by the CPUID bit described above, encompasses both supervisor and userspace support for shadow stack. In near future patches, only userspace shadow stack will be enabled. In expectation of future supervisor shadow stack support, create a software CPU capability to enumerate kernel utilization of userspace shadow stack support. This user shadow stack bit should depend on the HW "shstk" capability and that logic will be implemented in future patches. Tested-by: Pengfei Xu Tested-by: John Allen Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook Reviewed-by: Kees Cook --- v5: - Drop "shstk" from cpuinfo (Boris) - Remove capitalization on shadow stack (Boris) v3: - Add user specific shadow stack cpu cap (Andrew Cooper) - Drop reviewed-bys from Boris and Kees due to the above change. v2: - Remove IBT reference in commit log (Kees) - Describe xsaves dependency using text from (Dave) v1: - Remove IBT, can be added in a follow on IBT series. arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/kernel/cpu/cpuid-deps.c | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 7b319acda31a..a8551b6c8041 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -307,6 +307,7 @@ #define X86_FEATURE_SGX_EDECCSSA (11*32+18) /* "" SGX EDECCSSA user leaf function */ #define X86_FEATURE_CALL_DEPTH (11*32+19) /* "" Call depth tracking for RSB stuffing */ #define X86_FEATURE_MSR_TSX_CTRL (11*32+20) /* "" MSR IA32_TSX_CTRL (Intel) implemented */ +#define X86_FEATURE_USER_SHSTK (11*32+21) /* Shadow stack support for user mode applications */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ @@ -373,6 +374,7 @@ #define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5) /* UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6) /* Additional AVX512 Vector Bit Manipulation Instructions */ +#define X86_FEATURE_SHSTK (16*32+ 7) /* "" Shadow stack */ #define X86_FEATURE_GFNI (16*32+ 8) /* Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9) /* Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10) /* Carry-Less Multiplication Double Quadword */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index 5dfa4fb76f4b..505f78ddca82 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -99,6 +99,12 @@ # define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31)) #endif +#ifdef CONFIG_X86_USER_SHADOW_STACK +#define DISABLE_USER_SHSTK 0 +#else +#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31)) +#endif + /* * Make sure to add features to the correct mask */ @@ -114,7 +120,7 @@ #define DISABLED_MASK9 (DISABLE_SGX) #define DISABLED_MASK10 0 #define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \ - DISABLE_CALL_DEPTH_TRACKING) + DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK) #define DISABLED_MASK12 0 #define DISABLED_MASK13 0 #define DISABLED_MASK14 0 diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index d95221117129..c3e4e5246df9 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -79,6 +79,7 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_XFD, X86_FEATURE_XSAVES }, { X86_FEATURE_XFD, X86_FEATURE_XGETBV1 }, { X86_FEATURE_AMX_TILE, X86_FEATURE_XFD }, + { X86_FEATURE_SHSTK, X86_FEATURE_XSAVES }, {} };