From patchwork Thu Sep 29 22:28:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 12994656 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 9D471C4332F for ; Thu, 29 Sep 2022 22:29:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D7C36B0074; Thu, 29 Sep 2022 18:29:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3600D8D0001; Thu, 29 Sep 2022 18:29:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 161EA6B0078; Thu, 29 Sep 2022 18:29:53 -0400 (EDT) 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 091786B0074 for ; Thu, 29 Sep 2022 18:29:53 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C394041379 for ; Thu, 29 Sep 2022 22:29:52 +0000 (UTC) X-FDA: 79966566624.28.D578B45 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf12.hostedemail.com (Postfix) with ESMTP id 3373A40004 for ; Thu, 29 Sep 2022 22:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664490592; x=1696026592; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=LROLd1DXeI67ae2qnslC9c0J7dEIWigwReKeDsym990=; b=NAxXXU1kiNaa+/BRHssfizFdzWgwe67Q19ePN7YNM5ymHWKbZDNfNut7 Oi7OluOCpT22/D61Z99z6HwjrGewnW/V6hIDlE7ahAeBimPA4drGj1OwG 70+IE7Q2L/IOuJDjlpMnYEPuQeR+gm/GrXafqL9y5f1lkcF8TQSR3H0uw o5fuYxUVOr40lihHikT1RuEYC1EbvBNdZInaogv27afWi5fztl1D9LmZc ErKDGtmmZJkZ8pGEln1jiAPYv2Z+GU/oBP4y56X3RqhCnGCfB2oVkyK8N 2rh+sIAddsXjqa6h5OK0eaYZvFSRb4e2aaH30qhfZ1Q0jx8uC8UKgFmZT Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328420311" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="328420311" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:29:50 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="691016074" X-IronPort-AV: E=Sophos;i="5.93,356,1654585200"; d="scan'208";a="691016074" Received: from sergungo-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.251.25.88]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 15:29:48 -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 , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v2 02/39] x86/cet/shstk: Add Kconfig option for Shadow Stack Date: Thu, 29 Sep 2022 15:28:59 -0700 Message-Id: <20220929222936.14584-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220929222936.14584-1-rick.p.edgecombe@intel.com> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664490592; a=rsa-sha256; cv=none; b=XgeT+5mj7lZlaYVl4arhv8/Ws+akuwCx1JyENRFspN4Nusq25IcXNX+TaRixGlV55rn1ru JhJU6aNM536UO40wzluo/W82FPYxszv19vb35h0se587tGNPPODx4n6I1uOqx48xkbtCxt 0k9Q0Nw/aJFEZDFMdCmjr0/k3H43IkI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=NAxXXU1k; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 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=1664490592; 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=zJrzKUJqqQt+ShwooMSXDPE4Q2qA9Kmom53Abesu9Fs=; b=Kmy2RHqDQj1h61EhEjFNj0MvhCMQyd7BNhtcmCtG0DeM1IwKQN5YFum7X/0SgTcr0Duhq4 Q7slZmxUU3fokd+/xFN2uZsvAFCTzQTigRNOPkbf+jbvmSnrms8FJwhlr/BYYbqMYuXe9K FtBlXrPLfdSOZsXzH12PTjjWUr2JDyY= X-Rspamd-Queue-Id: 3373A40004 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=NAxXXU1k; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf12.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com X-Rspamd-Server: rspam03 X-Stat-Signature: 3kacfpnp7pzednisnugw65mfobafhbrd X-HE-Tag: 1664490591-243 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 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. Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook --- 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. Yu-cheng v24: - Update for the splitting X86_CET to X86_SHADOW_STACK and X86_IBT. arch/x86/Kconfig | 18 ++++++++++++++++++ arch/x86/Kconfig.assembler | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f9920f1341c8..b68eb75887b8 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -26,6 +26,7 @@ config X86_64 depends on 64BIT # Options that are inherently 64-bit kernel only: select ARCH_HAS_GIGANTIC_PAGE + select ARCH_HAS_SHADOW_STACK select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_USE_CMPXCHG_LOCKREF select HAVE_ARCH_SOFT_DIRTY @@ -1936,6 +1937,23 @@ config X86_SGX If unsure, say N. +config ARCH_HAS_SHADOW_STACK + def_bool n + +config X86_SHADOW_STACK + prompt "X86 Shadow Stack" + def_bool n + depends on ARCH_HAS_SHADOW_STACK + select ARCH_USES_HIGH_VMA_FLAGS + help + Shadow Stack protection is a hardware feature that detects function + return address corruption. Today the kernel's support is limited to + virtualizing it in KVM guests. + + CPUs supporting shadow stacks were first released in 2020. + + 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