From patchwork Sat Feb 18 21:13:54 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: 13145640 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 AC2C3C6379F for ; Sat, 18 Feb 2023 21:16:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6351E6B0074; Sat, 18 Feb 2023 16:16:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 609646B0075; Sat, 18 Feb 2023 16:16:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 398AD6B0078; Sat, 18 Feb 2023 16:16:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 218176B0074 for ; Sat, 18 Feb 2023 16:16:05 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D46B816053D for ; Sat, 18 Feb 2023 21:16:04 +0000 (UTC) X-FDA: 80481670248.06.F94E119 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf25.hostedemail.com (Postfix) with ESMTP id 965EBA001F for ; Sat, 18 Feb 2023 21:16:02 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hm+c9wwq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 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=1676754963; 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=sD7IX5vgBO4fM0jG6hc8nWvqQVD7JOaDFzg2SU6zIdM=; b=HJGIzAbmX78Afx+SIIbHhk/FqasOH7Fexa8CNdY5Qnc6Hkvm2WVAEMpT6r9oazrQJ/eAM7 rd1Jgh1ADpK5rISClWll5QqQ3VR+DPeEdib/JEMJ7FVFaF4lmYT7Cx9oH46Wmig715atZB VwiMfRSm2oHk7yhVZgZZypDekguKoEc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=hm+c9wwq; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf25.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676754963; a=rsa-sha256; cv=none; b=5dNdxdpLFYv3rDwCWbBI+1iOkzc6itFZZBPFcEbqGoj4qrQDZ+WA8ygy+nwbvD+Ue4EQRO Bi6K9SopbLL8s30NISPQH4Rhd9jGP46THQQI/ixudoSfCz3TAgZEARB/pM4UDlUlIgdfJ+ A953OYth9H2SqknsqK/3oGasWCXbAAI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676754962; x=1708290962; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=4iLM/QQV8kQnF+xZq53uEjXr+ZUWXLeX39BIgsKBw78=; b=hm+c9wwqgXUVEQOboElX0ToCTBC8BZcc2PddQLk6TkVQ8bSR+I01W/Pr AVTOhkalxO5bH4RlcuOc+ZA3a+OELFgwCTxHEi5it/lzPzBnh016GkjWL gX/Ss6rno3RcafVrWsQH2izNLA7wRSApljW+Z044LjkopIXHy1KnNzc+T f0pZ941WhffdguonZ4YJZRiP3Buep3J/iyOo53HHzMkLa9t2hUzaZPKLe 4Z/Zl3N8p/jdAPu92yGBP3N0H2TGROZwJZ7tEPFE2PSNwym3DiA2e1fIM ifutOUIvDLnrxKXiGpVMQwlBQ8Mu2lOP+mW6McwhAvXfL+gNUbF0am/kp g==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427122" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427122" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:15:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="664241574" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="664241574" Received: from adityava-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.80.223]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:15:57 -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 v6 02/41] x86/shstk: Add Kconfig option for shadow stack Date: Sat, 18 Feb 2023 13:13:54 -0800 Message-Id: <20230218211433.26859-3-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230218211433.26859-1-rick.p.edgecombe@intel.com> References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: 965EBA001F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: oy1nam7qbrhj1uu6e3mjwqwbfrgz5kee X-HE-Tag: 1676754962-405559 X-HE-Meta: U2FsdGVkX19zck0DPiyGbLxeGz/VNzSDzk7cTijBDFTEa6RKsyk5VzH7TP472UjOcdLwohnsUkl+6Lgcmpcvhh2o99FOgW0z18Gd3xmhSaWBNzdqJgBVUaU7/vID/uvL2AgaDQODlSdUWg2UP2ysnQOLWcO/oPjIAfoz/Ax4KbEMDBFvA8jKd8ru7gGZZthVXH2rfqvaceKHLQfN6peth2RFt247Au/C97AmflhYUvOQDdVopKIzgQBGvoVhlblRUhaWKuKn5tLThm1xSq2lMr41AEwiBOq405Ivbe2hy/038p59gbZXSBSxycRrOc/tyu6Ur6AwPbBMz5JhYtvVTHOt40IhRafD4TxAu2wC5FVC0sEaNaRguc4bRElU429Kbct7OTfGLWyj4DTseuEgP6bZdoD9wMuhx+G/qjqSezRMyLoo1ZEn+Qa6CTVLSqlT3py9pkLXzLE1P9dlmnniSeeTDmI1Yze6dGrFK1dTy9mGv9gngem+Ak+16aFkM70pIbypYQrqCr6ZIjgCKw2Olynyz0z4J3qFbfXQWtoON3mCM5kJBuVxE9Cuwr5acxq/FFXyC0Aj6O+bneOQNuT9BJhUGmeT6T/M1gKFGIbQ82GflGtL4n/sTK3I9q4pt/PyqYaNG0B8lG9BOnt/3eXYijXHAXp8ymPuewh99kCkFVCuMnN+azDtCEih7PUQjXWpasXubFsdBChdBSKanqheVkt1C+oYcswc7aLju6qm0zUOBS8Cz1dXPjZ9RslsWtL5vUffpZTaiPm9HlgPNVlrocgJbr+7WxWPWgv0bCCQRraEd8zMc4NdPqmFmFNzVd1lyqoOhBPfs/G/BZCII/7Tz31DRqwLsrZdyjll9MJCcplreQ7ya9Ajn5rAYdaDSLi3MpU6QohuxjvbpNIQQDyrQNHy2wF07zOArxnfAxs+tLaVbI1tzIaB8ZVReSJW7P8r0X4ReuTPZeOsd4goKiO 57WeurbQ lfDS0GJ8L4AWL4kscN6OeIkEU0wWIw252UnKAeKZ3xL/pda7jn2qQ5mN+aN1GXy6Q1poqsPxgMpLpJqFWgZpaQ3P2JT+iHFC96M47Q4Px5lhPbvj9tHq1Lrubzc1rD57FW1A6TfqdjQhGJIbNAhBI++CDSfiIeSFYI2cJftCC0k1770AjVkYicWjelk5YCqhiaJDVdtecdJTR6bWY8JlONZuKPPkZweADu05qakKr8d1mRULrfuRviDScUq2s/OV/10mYf4kV2bVoqlDgRw/FUrnPvQui0JanrAtITSOm7sUoAgb/wmNefZlqUA== 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 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 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