From patchwork Mon Feb 27 22:29:18 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: 13154233 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 7FA93C7EE33 for ; Mon, 27 Feb 2023 22:31:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 894C06B0075; Mon, 27 Feb 2023 17:31:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F5296B0078; Mon, 27 Feb 2023 17:31:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6476D6B007B; Mon, 27 Feb 2023 17:31:33 -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 4AA0E6B0075 for ; Mon, 27 Feb 2023 17:31:33 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 06A9D80B19 for ; Mon, 27 Feb 2023 22:31:33 +0000 (UTC) X-FDA: 80514519666.06.E1BA504 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf07.hostedemail.com (Postfix) with ESMTP id 13BEF40011 for ; Mon, 27 Feb 2023 22:31:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UYYDe0XA; spf=pass (imf07.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677537091; 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=YBXDrbHF64FKzHpmMbwe8SmzWZN2R6oOuvtFVnYBnws=; b=xMNrWkEYBkaDK/nxMNUJlSJcUCrai9/97Q3IAwnG8v38QTMrEWaIBQkp2cCurPneSFZeTU NG6U8LnXHD6cg+2sHIEuBlZ1fbr+Y6AKpvMCvqq/HUz7lTompvbIbtCtM5GmegihAekqXL JzZJEWPxG4IpcZ7c7QdWtoJut5TeyDc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UYYDe0XA; spf=pass (imf07.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677537091; a=rsa-sha256; cv=none; b=8gmeDeU31SwRkAt8LZvxv7ocjy0ora5Er1bo66jr30VntS9UxZYluR/sKPFYmzgcLTySPM U25aaKMwc5RZacuQuv5QSlNrSwDKpWJlmuAzXiQiAzO3p75mn8/30oIXA+U42Cfy3FdFo2 5TZQ0GHxSB0mvPcZ7kPq0Lzj+NsNWZw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537091; x=1709073091; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=lXB/Va8eFkKMhXnCWr4ZLsBS0D4WgDtbHK72wob+dBQ=; b=UYYDe0XAxW3rjPka/O3Ow3eSZzNSMpiajqranujPLO5fXJR436mX5kPT X5QaO1z4YiMfgRVmw8zNFFt7zErKjI2rSu60uIEw1/c5md5hJ+N3PM+Z4 8fKnRViioC9fSWATheil+hYDdM2VZKkcC1uySgu0L3dinhChMBrKrzJr5 vqXb4h+sF5senFiHBWe/bTqtbZ7KxV91RD7gTucXaUEabSD4bjXkaLik8 lC4kQzDkI5SI1xjxIcAq/m2K1fTTsR6YVcWHRP9Rz9XMH8pRoYZmlqSOa dBfkPLZt7SPd6w51ZCqkvaQYuSIs99XVm5kjZ4LJogQyQxm+oI8Sdy9Pp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657029" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657029" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:08 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024341" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024341" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:07 -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, Yu-cheng Yu Subject: [PATCH v7 02/41] x86/shstk: Add Kconfig option for shadow stack Date: Mon, 27 Feb 2023 14:29:18 -0800 Message-Id: <20230227222957.24501-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 13BEF40011 X-Stat-Signature: qci4aniewxzzdnngptqa86dq1wqu4b7d X-Rspam-User: X-HE-Tag: 1677537090-928050 X-HE-Meta: U2FsdGVkX1+9UzGbOadv/ebxKR5i149OXg/qz1zt7PgGVeOtXLsw7NUdDRB1Ywsn6oNeOi67SKA8TJRANGYCNoiIkVsplu7E34r8rSEtccESrix5tuzVNPKSA/fwHJfGPey0EElyi9oMoLPoNe+3m4mtiBt5SVZ0upWncDtqctE7DcgKHGrnybf3JaSL7hlBoLvtoXD1KJWdIy5Z2DvFwkNFhZrPAbhJceB4IFYNxrPTy0C7pNe3PHoofcz8eSuYB+x9I9+tU2dkcDlXX5FlUbw+7fZh1aPICirLvQO8FlJbxYzMMQwT2O4ph5GptgmhdvRENhgITbB34nGoZe//kYOxZ/6mF9KPIsUvf9sBNvi8l+AMmiLL4+x0EUSWBqDdu4lWUkbLXm6xi7rv09VPvnx9aZTa1N3mwizT0HJJQg7zJNy7tjYYV2b88BurYNDjc8NpLqlX3ZHpvlMTPyGXN6xRlFWXFGeL1rMEiIR0kZIAZoyxt3LBAz6j1GFulpvUEyqPeXV12rZzu5fsdQWSDy9hkeYl8LhocD72hxGBOhJ64qGr8YPKmBmln6Cy5a7w0sLAmXzZndV78F8pOE38TwvPeiAK8ovjFpQQxJO3lxMHhF+JlXNfsogGk0Q1l/MZeeAlTb7jwyjO1+0Xh43Ty3QAr1OUrVRH3T0HZh4a6xsp8oP6c2mm/ix78XpkzHjOovcN5hd5dRn7EsnykqC8JS0hTpYn2msbdZtYzTltIBmCKO3zoqPtC5LFx/xkyFLBquhpvEzCct4iMT1fBgfWKVGxNxaJSXh/lObiqNImq8RqpGEOxIGFmZnO/6Vv0gKt58jA/cRqJsUz33ZRJLR+9pRTEjHEgel9xtRF9vYQNyux+qhmvBKWJXOzA+F19EXPcmSOuqFVf5A4mq3GxF3PcVLHJqUlrSgvU5YLV5YUlmCrOsZQeJgFAiJ9Ia1p73yCZ7P7+V6C/o3xuPevXFk mqeyXQvq oyXJolIci8Tt/UyL+aSsZQ2YARHUmZCMpoe2SlFcyeTJoEeTCnE8Lnrezy0yQqMZGJ2Ov0Io/mk+PMDdytfhdYn5tldGbRTue1ahkA38ufXTDaRD5hYc0xMI6H3BsjdWyKVSDwTOVk4g7gHZDjbiBFqyLOBiO2UIo1FDcdYM8nS+P9PF4C8ocktmESspzZ7QzMTbEsJFp4UWVDjKBtgkU+dCVZTe/fQyjuMGY5kSOGJbYZRtGbm6Ihvc1+uaKFyVwfXrMJZdQ19LmuN+RopBtekwoXMAiprlB2rrxUdj1hYApp+Fwp01brHAa88HZjk+qqG1m3JB8ug2gVQjFib6QcesBJLedDcj511ElYso3bqhqG1qMZDdB6KQa+Q== 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 Shadow stack provides protection for applications against function return address corruption. It is active when the processor supports it, the kernel has CONFIG_X86_SHADOW_STACK enabled, and the application is built for the feature. This is only implemented for the 64-bit kernel. When it is enabled, legacy non-shadow stack applications continue to work, but without protection. Since there is another feature that utilizes CET (Kernel IBT) that will share implementation with shadow stacks, create CONFIG_CET to signify that at least one CET feature is configured. Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Kees Cook Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook --- v5: - Remove capitalization of shadow stack (Boris) v3: - Add X86_CET (Kees) - Add back WRUSS dependency (Kees) - Fix verbiage (Dave) - Change from promt to bool (Kirill) - Add more to commit log v2: - Remove already wrong kernel size increase info (tlgx) - Change prompt to remove "Intel" (tglx) - Update line about what CPUs are supported (Dave) Yu-cheng v25: - Remove X86_CET and use X86_SHADOW_STACK directly. --- arch/x86/Kconfig | 24 ++++++++++++++++++++++++ arch/x86/Kconfig.assembler | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index a825bf031f49..f03791b73f9f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1851,6 +1851,11 @@ config CC_HAS_IBT (CC_IS_CLANG && CLANG_VERSION >= 140000)) && \ $(as-instr,endbr64) +config X86_CET + def_bool n + help + CET features configured (Shadow stack or IBT) + config X86_KERNEL_IBT prompt "Indirect Branch Tracking" def_bool y @@ -1858,6 +1863,7 @@ config X86_KERNEL_IBT # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >= 140000 select OBJTOOL + select X86_CET help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity @@ -1952,6 +1958,24 @@ config X86_SGX If unsure, say N. +config X86_USER_SHADOW_STACK + bool "X86 userspace shadow stack" + depends on AS_WRUSS + depends on X86_64 + select ARCH_USES_HIGH_VMA_FLAGS + select X86_CET + help + Shadow stack protection is a hardware feature that detects function + return address corruption. This helps mitigate ROP attacks. + Applications must be enabled to use it, and old userspace does not + get protection "for free". + + CPUs supporting shadow stacks were first released in 2020. + + See Documentation/x86/shstk.rst for more information. + + If unsure, say N. + config EFI bool "EFI runtime service support" depends on ACPI diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler index b88f784cb02e..8ad41da301e5 100644 --- a/arch/x86/Kconfig.assembler +++ b/arch/x86/Kconfig.assembler @@ -24,3 +24,8 @@ config AS_GFNI def_bool $(as-instr,vgf2p8mulb %xmm0$(comma)%xmm1$(comma)%xmm2) help Supported by binutils >= 2.30 and LLVM integrated assembler + +config AS_WRUSS + def_bool $(as-instr,wrussq %rax$(comma)(%rbx)) + help + Supported by binutils >= 2.31 and LLVM integrated assembler