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: 71672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp527915wrt; Sat, 18 Mar 2023 18:20:08 -0700 (PDT) X-Google-Smtp-Source: AK7set+y/MvSdq7MrohL3/XXwmU6xpMkXHnRXFW0jqChzgHj4PT+vbGR0lfVMx5TphsACz/iLQVC X-Received: by 2002:a05:6a21:3395:b0:d6:f08c:47b2 with SMTP id yy21-20020a056a21339500b000d6f08c47b2mr14856287pzb.8.1679188808236; Sat, 18 Mar 2023 18:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679188808; cv=none; d=google.com; s=arc-20160816; b=ZGuw5D2BxyJ76tgQ2V+3WfBnyfB1dr+wIeV3r0Hu7d5kRd76tHkmAufOihlJLPDRDD AA0ssnSMIsKhIs5S4y39hoy+mg1sMtHSgMv/Erz/qfOLd1AxrNCxZaLotqhyA/H3d5Pa DlLutyVZbDIh72rC68+vgCgKRTDtFG+2BU5pCfH4OFPbPSSgdHgqjNnOkEt25WRWRb9C m8qmCEeMaNVQmj4KcumCz+s1Cj4Z3kfN1WHPBns3kbQLNRw2W7WhTPHdbSbGDbQmwTEO hnNRlCVTygGbOn4QF9G23xjOoBSvSeiG8YTw6AW1i/5MXIoh1yUJayasq7+XuRy80fCu KTlA== 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=VkrxRxNRr4BKJw2j76aUuVqNLhkKJerjZq1QQHk+4g4=; b=fAv1OQix9pZQSfgdqGZPMocJuMJ7rRmdNNCmYz5cyPbB5Uo4fXihhSBo9vxLQes7+8 kMFVZEPh5hFEP49xEzUXiuuB8R3+OZMbT4yIgrKr6cItc8R5Wwa8fbtUgSq+7TzRQKrq nMD62PZ+KEb4IGsl6XHcmCSUyTVy5UZPGtvy/Pts7/U+zivfqceiFF9q7TFBZZ7srkKr 7qCN8wAZpdB5AQ8OccvffmxkxLe2oY8X5s0S9Nplj7p2KSEddBNwbgER60VGRLech2lM 2hO4CXmTpYOO6xbYwB/V4sBaiHbf664z2jjGtnm1sW2FgqfqjLlkmEflkgarKVrLVRZ4 uivQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Wq/d1W0O"; 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 o8-20020a656148000000b00502fd16cd1csi6543680pgv.367.2023.03.18.18.19.55; Sat, 18 Mar 2023 18:20:08 -0700 (PDT) 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="Wq/d1W0O"; 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 S229778AbjCSAQI (ORCPT + 99 others); Sat, 18 Mar 2023 20:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjCSAP7 (ORCPT ); Sat, 18 Mar 2023 20:15:59 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29ACC28879; Sat, 18 Mar 2023 17:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679184958; x=1710720958; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=r28jIOtA/K6D8osNwQJhDgDdLXhK5+vr3NOhbtj47RE=; b=Wq/d1W0Oqa951uHliAqWQtV5pNgQyOyI6UWbXuUpEpnxpkLBNZ4mUhw9 VXR1GMMXvs7RC97C7JaaDZRk4sCBsBE16v2MWkERSW75/eLxJlQhAdJ7f ArhSjq23DtTxy7E/86y82KT/9jErxrTIkStnx4ME1kmF2HXeVVEdw4NsP nHcGbehd8PMVoqs0lQvA1GIsHwhPtUONphVjV5zv0DBeHAxzABTnWxCXZ 0cmaHXmOR1qKrOQsA8fJMv+VAlWKjHYLPHHLiHzAD1ZfIPOHtztL6Jkz/ kC0Q3XjN625SAd+NDN3cdQWR0OnvtsOWU1VyoH7d/OEW9J4sy8LWzgSVz w==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338490756" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338490756" 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-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_NONE,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?1760757083912952241?= X-GMAIL-MSGID: =?utf-8?q?1760757083912952241?= 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