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: 58991 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp554420wrn; Sat, 18 Feb 2023 13:18:28 -0800 (PST) X-Google-Smtp-Source: AK7set8By435EFWw8AXJN1IFaneK9hTYHV3tT+V0jWok22rseW5lqc6Aw0kJJnp4JCAmqongNSNh X-Received: by 2002:a17:90b:1806:b0:234:a9df:db96 with SMTP id lw6-20020a17090b180600b00234a9dfdb96mr69384pjb.33.1676755107932; Sat, 18 Feb 2023 13:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676755107; cv=none; d=google.com; s=arc-20160816; b=kzIilwOO+6H/RVXdw1fM6K44Q1TvhHPykB101VMufjxGYAA2omk37UuFdgzsrHProe TV/+k0+La1DRGvTnQOJxiWgGR6MVo8pu5BCx0QeavAGjzcLYPNzWtBZ1iSJfas7SIc18 ZSZ/QHMNBnhqW85BbbZM+p0LqIZukDJ49DIZ/Op/+vYvQY3DL2vXbaAb33bBONkXGjLk wkfDy5bdylqZ130adSdN1tqp2nXk4el6B9y+m5w2qJzNJGsO0x6+fvES8vCRu3aId7t6 n1NBxA7Qb4LwKy1FkqzOD7G8oODGqQBUxhjU6YdFXctIYSm7Ql8Sd473IjPen9EaxlfM draw== 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=sD7IX5vgBO4fM0jG6hc8nWvqQVD7JOaDFzg2SU6zIdM=; b=Hk5vP9rJWZxY6Vnp/eCoi1C/o1+77CGq+mDxVqj2X7Ff19ctzW3XMzvoLEB1T3emaB 7Ss8S5ylef4AUB3hq4S0PnJOFJ4e6lmGNkMhW8cbldgjufSiykzrcMBDd6koIUXWMhNG dkmhl4cn9e5QtuffD80jzPtLLgW37dMeBKWQoiSkNyTOMDDKFO3EBVteKslhzgYTBWEb HtoIBoOYfiBJaesdcJo5xrcLgPUNiFsMslWjAKCPVhQ1x2H6gN9PhtZ2fCDzbiHbLXb9 PuEghC6fLoaXrvSvwJT3gFtA88Kzc8M3K8ra8IFhOEo/bU+kqT5Cb8A8Sr3VmWKbNA7v HMpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UYWK4qS9; 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 cv14-20020a17090afd0e00b00230c82c6284si9476092pjb.19.2023.02.18.13.18.15; Sat, 18 Feb 2023 13:18:27 -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=UYWK4qS9; 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 S229886AbjBRVQg (ORCPT + 99 others); Sat, 18 Feb 2023 16:16:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjBRVQJ (ORCPT ); Sat, 18 Feb 2023 16:16:09 -0500 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC47B166C3; Sat, 18 Feb 2023 13:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676754960; x=1708290960; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=4iLM/QQV8kQnF+xZq53uEjXr+ZUWXLeX39BIgsKBw78=; b=UYWK4qS9pRlRSm6vLHK9dWhs9y4z2+bFXn91rlk6kxD/wMBJpwvGZXZT Hpuww398fbhMUf4Tq/VU4NoxrQkL7Vepb42GHMXBHrX5Kwxxk7qiQYR3t z0yHhrstH3e5sHMABQzDsZ+2cWnNSqhdcqVR6wdECPsKrxfp4Yx/FghDl i1gFdhJXxGLLH1UZ6oiA/zz5j+Lm0QX7xoejctE9X+DLbpXb+YAEkoqwp 8+mOp8Sy+RjL+9ZDyfKlNdsPSzu1Sq0S8IN3kSMC2Wis9ScyDdJYIXzms MxqQcYcpN9NefDC9Tr5xF/agmQIsB8csW5fISxjccF4y9IUWRgyv/OO1t A==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427115" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427115" 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-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?1758205164044286545?= X-GMAIL-MSGID: =?utf-8?q?1758205164044286545?= 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