From patchwork Sun Mar 19 00:14:57 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: 13180130 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 7D17AC77B60 for ; Sun, 19 Mar 2023 00:16:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 448B9900005; Sat, 18 Mar 2023 20:16:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC6C900004; Sat, 18 Mar 2023 20:16:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24668900005; Sat, 18 Mar 2023 20:16:02 -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 0B0B0900004 for ; Sat, 18 Mar 2023 20:16:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BFE7F40C82 for ; Sun, 19 Mar 2023 00:16:01 +0000 (UTC) X-FDA: 80583730122.26.C43E14C Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf03.hostedemail.com (Postfix) with ESMTP id C499A20008 for ; Sun, 19 Mar 2023 00:15:59 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YqCCtIys; spf=pass (imf03.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 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=1679184960; 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=VkrxRxNRr4BKJw2j76aUuVqNLhkKJerjZq1QQHk+4g4=; b=YAM+tIO5RBU6yz0BpE+e4NWfZTUaILnL9XiunCfZ71nprfDCi31kSmVlbBRQ8bSlZTk6Xy jZKLwu874TqR441jCqJUaHWIxfG2LhM+FV94Wlfet/9IqimzjjXgPN46NNATsX3RbPecok oE/D5GsPqCD/cKcZWnPkDVJubgRu+2Y= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YqCCtIys; spf=pass (imf03.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.115 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=1679184960; a=rsa-sha256; cv=none; b=QXt8pbiIpfAmjf1qdunFqQbaw9IaIZ1xjEFUMR3swwcLUOCteBA+TjQas97m15Buz67Yrd XarwY1P5X8ccphmsMzPWmGD+G9j6/+iLBKrsr+LmBlIV6md/BL2grlGroxzJZ6pT5IFZqr URLbOuJER5U/KF3Vh3nMh4bCEsewG5U= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679184959; x=1710720959; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=r28jIOtA/K6D8osNwQJhDgDdLXhK5+vr3NOhbtj47RE=; b=YqCCtIysJapZ4ZpeDk7CC52G2FAeRwfCK5KgddlQpnTm6gBUWSj1m0VH vk93XFs/pHkUR5TbSdRuz5vlmqjlG+/vJUonB0EmEw+jEm/BIlnIeKkIO y96lq6vHilfUhtE0ynalFfHZHJBNIfU3sHnSIqpaV1WFcwAUzZ4HJl8vD cXnkeyPU9exv3Pygy+A4rzw3F1hCaZjBHZROjxM3OJcAVmsXwcYDTkxeA VlbuxpHnIl3+T3A+3oUA5zDZ/tu0+55gbJGC1igCzfWBL9591fQaJdS0T PHPRi/8lMBQcnjx1WZzRSzRRZX9qTcLFVxMBP/oB3bh0Q4tqE0tjWDuXg Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338490768" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338490768" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:15:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="749672771" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="749672771" Received: from bmahatwo-mobl1.gar.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.135.34.5]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:15:56 -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 Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v8 02/40] x86/shstk: Add Kconfig option for shadow stack Date: Sat, 18 Mar 2023 17:14:57 -0700 Message-Id: <20230319001535.23210-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com> References: <20230319001535.23210-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: C499A20008 X-Stat-Signature: o7ofam41pg4okuipi33nq7uchxjjjmee X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679184959-957588 X-HE-Meta: U2FsdGVkX19zcPoeLOsgASm5JCGTza9XUH/iWV+Bpr6zuna2tEpmFPVqQrh8KVnrbWnboDdaeoEtI4vbD5fIgAOE5BWNleO4B5uKZHDXrcVUqYaJdubI+rOC0xBYT7U7mPT1/TY5hb7+Kc1gFAflK7rYdoJCSi5NW1NJkU/LCBjBivjeacyreZZEHVxMq/Jsf2rFo6YNW29qkTFEpzCUC9gv5f85pXYX7JySz1l/MhUS+1xsx8uQKJtXH1ZQAs14kEN5tRJ4b+QNupwv3HLVOyOsCbJr0Ngu+iIl5ujjLJFYMV3PxwTsX6cY6S4pINlCTi0y2a7qCmlMngSVt+SlM70ovQrK1xJZFJImiOo9Eo4FtiHYjkjl0vrB9Y3dUuGGsxrXfENfng3SbyOvw/Sup0ARTWCTaQ2xtwE/cGTQCbplSg18dBtwjI8+ELMYBqCg84jDr9q7ewYRySL4Ch6ctCkiNJN+9rqoswdquLDYZci5VRAtQWqPB0fpqd4nIr8NxTE5FOgrnt57zeCPGZ7sf0EJ27oHCTshQ/AEhOgOuAJug0Ho/pquVcAurXIMkfsZyuk/Wet5sbmDJbD7j//J48NmMGZYsLiS3Ds0cv1oOBAgOyNmC9gh/EW03KLy4pfeAJvGPllwrBNWPh0chy8tHpLPJ9eiV+Nfft2ek3uoZNdb4BmOtA11Qjc6xxk1WjnFH50k4NnZ+Cf2/rnFsWHrsBSulKZO9SNSCxDlNaFYtklRSA++cn2jCGFGJvEEzwSCvaQs64Wn5lxnTy8DqAIt+tvLNJX9IJ50LjZgBpldcgJuvAEiJ92UpzC2t6zdXma/DWyM9w/2VT2JwmL9fCCo4zdMioiTEIML+tyQm6ic6+hVET3N/6Ovp7L9u+MCTqMzgKE+cwATQz7ntooG1oYhbJy+1qonV0HkL0ybizCWgrj6aIAP1JB0vJr7zMwG+H7kPzS0XdzpbJ9AEOdW2Yj +HVqyMRU 4UI0Uo9sbftMpEnnLY0zmx4Wz+cACJ0bRRfS6qCfbc6Q/9sNy74kz1BZb0boR2MharWA5391yK+t4wBp+mCzCx5UrDEV9N66T5PVWK88X+YkabOd2e4VBFbtTPFYGHLmAmKGPRbgKLQarP3xOIFRv8lykJ5ZdNUOZ7XP8FtR2iEBHdgbLe/iLbOkC3LrFg6Mzc7odNh4NIcduK2Z+ZsOnjKW9SxPZLeWRzy1RcYRmQFN2iWZKmr28a8K9CnKGxSmROOjoHuf1pg/Qi5+qzHa4j41szsqNEuGuoaYbvHjvYYdDchsK2TU1lWaCNSuDCdNiSZOraltwNflg1XWucYUdwunrUITHlFdhXLKXXjaAWylqfwVc/Yh/dTqR1g== 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: 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. Co-developed-by: Yu-cheng Yu Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-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 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