From patchwork Thu Jan 19 21:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13108778 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 42EA3C6379F for ; Thu, 19 Jan 2023 21:23:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 550BA6B0078; Thu, 19 Jan 2023 16:23:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B2136B007B; Thu, 19 Jan 2023 16:23:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 306046B007D; Thu, 19 Jan 2023 16:23:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 10C346B0078 for ; Thu, 19 Jan 2023 16:23:31 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DEC7040A2C for ; Thu, 19 Jan 2023 21:23:30 +0000 (UTC) X-FDA: 80372824980.11.89A468A Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf29.hostedemail.com (Postfix) with ESMTP id 0681C12000A for ; Thu, 19 Jan 2023 21:23:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PB7jOnoy; spf=pass (imf29.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 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=1674163409; a=rsa-sha256; cv=none; b=iRK/emMrUSLwh1FBGZuK5cnhYUoLBDwpDwPnZFKq6thEMNn3KH3lGTNkzTIzP6PB76E4gX UZjEBqvSCzk+A55Rh80B3fkiTVPQdZ7MCA3a1OWJLGFAyhZiNwsDgcagC5wNLJA06xT4WO a+ArnSsCQE+ZAg2asIaZRj29YpsXQQs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PB7jOnoy; spf=pass (imf29.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 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=1674163409; 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=3U7z+h3YDF8Sba0ajewGuAx6MSy1V++Xb+AytMN0PuA=; b=jeHy+m2VWadzMj1XF3vzi1Dpm82Tim6hYfpPW9LzCBiD5engME7ZXxJ36XB8XU6+j9Z8Z3 s//oOtsqdLLyZATRrq5itpWxv+S4F0/gzgJMDQKP8B6XXczVdg+9xGSqpYucwsv5zmjeLt fy5/6ieH6oD0+swDPS6ZL+ROskLjmWM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674163409; x=1705699409; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=qg2fCiCJOKwg0sz79Qyr0Ky5ojS7yp2AsnYDlj2uU6w=; b=PB7jOnoyfC7YPNuEmTTG9NcAS/zT9eg/VD25mEVtXzqoz5FCLr6jpyXS 44t7m0+ozTojCRra7v8j3/tv+1+VuEXHIlU3GGEJpwFkGIZAuy6dlOsOz NntunsOu8DwKCCb4n9r8XGlgic5jwuYzHFMYAYzcNEqsfsEfp3QCz+dwa cLJVTgBYhHWULlP+AjfZzofggY1Mud6feMebfyDMqekkeMpo5cCJhlHiC 8Os9MFpQ3EF7m3HLbSuCA/uiren7YQpAtpBckDx5wIzsE5oXltVa8I/JI AMKtRg340OXROVLvAUiYNiLfK72ISkxij2rVbpswFGl3Zws5AwmJnahsn Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="323119198" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="323119198" 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:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="989138990" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="989138990" 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:26 -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 02/39] x86/shstk: Add Kconfig option for shadow stack Date: Thu, 19 Jan 2023 13:22:40 -0800 Message-Id: <20230119212317.8324-3-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-Queue-Id: 0681C12000A X-Rspamd-Server: rspam01 X-Stat-Signature: szrizaqwcxe3djnyoncdadrjojty9sje X-HE-Tag: 1674163408-43147 X-HE-Meta: U2FsdGVkX1/bBPILc6vO6sx7iCf2RAEjPqFl6F5DEolqQggi607UyySDQYVqGHM3G5GPuaGTj9K1jgSghR1DS2yzJiT6OtIF8UWlPNeHSu4LyTXYaZJHDfKwmqzfIJZjA+F/16YByWWFoeJn3pDr9TIX9sUaKqTvEgwUyAzW4AR6MZcT6EbHGRG7Y4FSBkaYwtxY4pGouyuaz1DJSeIQUNVRRF4pe252C/nQvJTKljFzeNpMtOloaMcr5HXNO+d+sMcvf8N13t/s6BQ+kGrDNNtyPklgOwMzkd1cMtpFN9/h+07jiQeW4FJyajSrzrgokzy+7Xtxt/NtGW9AsLBHgwR0EVv080B3GrD2t5QsP1X4rFSdgCgqghej3A3IxEEPnnoQP2tkNE9ydfOAkJ7rmqTOifEUKFvvF6iFy7gPDB6KJu4HObwZdotqX8P4zJtcjfzbhG6yD9NtpmOC2NP+bAzGqAUIYGrsQyceDVqbR01cKOea9Mi6kbUyu35toSbyx1IwKg6khGuqVfdndREah9o3g47Y/zzGD96DvVA1TsXb0rCVmefIeaM/2Irr15yBMbDGkAbzmDH7+6YzUzOf1CnGiKZjx/nsmi6sgbet3PM26uzXs1kCV5x58J7hQSVcZkX+ayWF30aBagiWO0p2uF5p/S54D+cJ4QqV36t8s3LCDp+tRD3i8V/U/3ZlCLzAtAJZcvtExWRIIQYOlm5ulYfZVXV77njCZCnCHlFdOnU3uXRIzTia2DbWjHwqM2Dg8axw94Z4UZrnem+GOS3uon6Ot3rXK+zC6ODFehuAMqHg1BGZNyRM2gyjU2fK2xeonncKqjiofmgAybxYnMuuBxRCE+ia921k1Rb6FF6JoK1yUeMLWkGy+wtf4ZWYN82B5suTPF+0uNXm83X8T/2YbF0aoswibFjYSGaz618UowmLecydX+27+qKDQHGmM8MS0jdCNdZ/xkOb9dgoW5M ulTbTiBM SlKm++qx9aQ37cyhHJ1pe3MzG7Jlg2gfmvBiQFbG+FmJpIKLf2As3zvNuCysINHTD7IapzjaSONQub8ERgM6zwL1dmDRNVtepy03E2eDnYlaXw30ax2vrH1imxI3VsPjr4NqIyOm1X0WcuYhmRKl4KkOi0MibphEYy356Hy1VaUz7o7yW1KOwdpef2csr9gXo/cVXvBBVqvTh9Lwasv1duS51v7ne4pduRXnZVF4vutZ6KKKJNm/0oogNuSxMuRlxlQk18ecB+5u+QY1k/eGkAy7HY/HcLCIRm+S96WGoVtcmvf0d0ec2CpS+Fw== 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 Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook Reviewed-by: 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 3604074a878b..d0037181bc15 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 26b8c08e2fc4..00c79dd93651 100644 --- a/arch/x86/Kconfig.assembler +++ b/arch/x86/Kconfig.assembler @@ -19,3 +19,8 @@ config AS_TPAUSE def_bool $(as-instr,tpause %ecx) help Supported by binutils >= 2.31.1 and LLVM integrated assembler >= V7 + +config AS_WRUSS + def_bool $(as-instr,wrussq %rax$(comma)(%rbx)) + help + Supported by binutils >= 2.31 and LLVM integrated assembler