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: 62158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2682552wrd; Mon, 27 Feb 2023 14:34:08 -0800 (PST) X-Google-Smtp-Source: AK7set8P82JYDzuinnIhwAAx6GQ8vyi8WSVm4WU/xVFcq6d/PWtP1/Tp+L0VZvc+tUSCZyXQyzpf X-Received: by 2002:a17:906:2f89:b0:878:5bce:291a with SMTP id w9-20020a1709062f8900b008785bce291amr302290eji.36.1677537248333; Mon, 27 Feb 2023 14:34:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677537248; cv=none; d=google.com; s=arc-20160816; b=DMvWFc5XDszIDo4fNg0Cni97/+O2IJ2QeJjxZ6Ih/TMaFVr2wla+JK6s/4OIDJY636 16gI5wt9DpAF6LIUbeyXinEzL9LH2uJwIFOikP3a4a1534OrFNVz8HwshPXy+AHrPfVO xKZSCipBuajTo99i+HER4dk4zFeL11M2bWAzhevdytSgxZy0n+CIo5lbUUYJ44IJh/cP sTnDSueBSEPDWDGDKdVQfOt3PO83z47/zUbGBVE9Xg7cR4jNMsyx1ZTOsOsoCbTvytzu J1W0z/B63LKhI/JW/wwUNtXOh/EzPus2BS0pgz2lFds3T2oLWdJyMtJkwsJjFLUZrfPe WaOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=YBXDrbHF64FKzHpmMbwe8SmzWZN2R6oOuvtFVnYBnws=; b=pPOTpGNE3iJPGYHuMKoA7m5uIdtlrAWe1pEKSnqfcyUqjnWzz6tcTVcP8ZXHvHw5WB /VYloI04psw9oDIriZXBKYPExm7z1VV1g+QiXqY4vIe5o62xXSTr1vSYX/GbX3G/Gs8j p8ec7NiW2GTWrXPS6UWlsaGjAN6t6uO60vNAODe9pI2oOoXRX+WCM6SnZaQJfYBTOcKY kdM3e/PC73ZWJqAAx6nAUobuBq7O1yH0t04nkWIije2MKGUO5ObBf40BysyEiMTpLGHL U8Meva+3Typ82k3erixqnD9WfpDy+dNeEensnvd55riTyTHiIQgBc+KQCW0GWq1fbayP EHIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FHGat0R3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gx2-20020a1709068a4200b008d5cd760cb6si9343001ejc.428.2023.02.27.14.33.44; Mon, 27 Feb 2023 14:34:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FHGat0R3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbjB0Wbm (ORCPT + 99 others); Mon, 27 Feb 2023 17:31:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjB0Wb3 (ORCPT ); Mon, 27 Feb 2023 17:31:29 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAA5228D09; Mon, 27 Feb 2023 14:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537088; x=1709073088; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=lXB/Va8eFkKMhXnCWr4ZLsBS0D4WgDtbHK72wob+dBQ=; b=FHGat0R3hl16SpK4tBDMcPvefkP/29zFzQr7AzMK7N57TWnr5BembDZa cnY0YrkfvpaQj4hgkBbfAzE+RwCIyqTlR8leMs6aT10oyxnwyOVynwr2h pp+slKeVWXnfD9b4qWXF/7ZtX5stYIBZGkpSBF25hcqFc2krsfFNP+XV5 t6ATnR7RsDJ6XjgrMsnrICHixZCw2UnTzf1dgCT98ddPW2zL28+Q53t/F I3lRGM6fJsexOypE27/RKtTD46LcnSiinHUvSiDprxczF1xVv+UCJXa8J THLFNyT68q1KjxYW73qQ+NNh91+NVSB36O/rf4yGkqhtyYxqsexpEFKbZ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657025" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657025" 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759025297816378748?= X-GMAIL-MSGID: =?utf-8?q?1759025297816378748?= 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