Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2514627rwr; Fri, 21 Apr 2023 09:52:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZRR/783mvCC3MPaKNcupTn+tA4ZC8lSrHsAIKWr3LMQrAoZ/MYtNQvCMxJhzAGO76sZjjO X-Received: by 2002:a05:6a00:2d96:b0:633:4c01:58b4 with SMTP id fb22-20020a056a002d9600b006334c0158b4mr6301411pfb.2.1682095946188; Fri, 21 Apr 2023 09:52:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682095946; cv=none; d=google.com; s=arc-20160816; b=xkSkbt8XwkO/JXFKUmYEvhh0C1O92L9ECM5XSZWrHUpcbXza3aH2GvPLlFEi9ubPYb Hk5/Gz6U6ighP/Dtd8Bx3UNqL027xauAIpE6jWfkLUdgfQUc0RhNZn2wIbV4q5P8Q30m E7ntXu++bOZj3mNZcdK0YnyjXY3iqgWlrwcu/XA8xJ1X3iwBeZqn7cAvb/rIuJ+m0vSc dmvY+ILzGr2EBzInUigKqc7mBtAPEzjyOKckX4yxWDjIdSJAyGtT+D1pBN+ED0VEV9Mx uNfTCQqfEI718iSNtu9LLguYUJWAHU8u7icw9fwtb/jZEFSF+3jF3x16CSWJuqxzviSs mhLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UsqvhISRt/CguHVi6xhbHsUhQIB1BzF/GvBGxi/xaQE=; b=poXSDAa4+S5rRrCXluyVZD41ed4QAD+ESVqSDZK2hqXZ1RFlReuSvDlYn0olyq4p9z wTOzcatMhs4r4Whxu2J5BemZpjttnMwQIhKMycIF2abJxvdv7Y5/uqf/HKmCzSVUhr9/ Zg0IegiR4fpvaCmesH46ZD6QqfjGhnNl3UrpYYdOC9dtHNgqHeve3FaMOAc68dKdykmE WXWp3/uP0mX4NKe+e019KaN0bDhmFqaMKPOcK9KIyW/YTyaLlpwSBJFy93jf5e9PqfnW u6sVi8+pmwkHBomimj8LVvGsuyr+C3slPQ4kZ/rYtSM569npSjfo9cB4O/Tuv4Tc6UBl RfGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="I/8cUpkj"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a63014c000000b0050f818e900dsi4428137pgb.761.2023.04.21.09.52.11; Fri, 21 Apr 2023 09:52:26 -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="I/8cUpkj"; 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 S233249AbjDUQuu (ORCPT + 99 others); Fri, 21 Apr 2023 12:50:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232934AbjDUQur (ORCPT ); Fri, 21 Apr 2023 12:50:47 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5B212586; Fri, 21 Apr 2023 09:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682095846; x=1713631846; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9rCJFBWLMwkBw9HBuP/Kc52dFcfvwQjY//PWWGqH99k=; b=I/8cUpkjsZLBADf6J2IkBrhChvyhPX/2eaXJe2uboCf4NIZMGWs7Bgvx 3+s0VxIRGE3Jk3CNGH7kXOXCuDABOLLuq3MJAgvrgXF50bf+GQ6R+kwAd GwMIWN9ly6onm83KKrWZ42e7BDzsn0KTYeOc766GSwt9jq+uMRwg36IyC clWgUDN+ZI04+vzi/1RpWlxpUaiDROUze160iiPEF2cWzyOeGLwrJQMQw DOrHlTthHzoYxr4W3UTDAbOXwGfAfrdQ/WaaWqu65fP28kf7nnZyLM3Ga czMOj6fwce8BDAqBy1rQ57E3bjDKQ7IeNbKwU4qrsxBz5I9k2g4Paflgu g==; X-IronPort-AV: E=McAfee;i="6600,9927,10687"; a="344786946" X-IronPort-AV: E=Sophos;i="5.99,214,1677571200"; d="scan'208";a="344786946" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2023 09:50:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10687"; a="722817355" X-IronPort-AV: E=Sophos;i="5.99,214,1677571200"; d="scan'208";a="722817355" Received: from embargo.jf.intel.com ([10.165.9.183]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2023 09:50:41 -0700 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, john.allen@amd.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: rick.p.edgecombe@intel.com, weijiang.yang@intel.com, Yu-cheng Yu , Borislav Petkov , Kees Cook , Mike Rapoport , Pengfei Xu Subject: [PATCH v2 01/21] x86/shstk: Add Kconfig option for shadow stack Date: Fri, 21 Apr 2023 09:45:55 -0400 Message-Id: <20230421134615.62539-2-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230421134615.62539-1-weijiang.yang@intel.com> References: <20230421134615.62539-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 From: Rick Edgecombe 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 Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230319001535.23210-3-rick.p.edgecombe%40intel.com --- 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 -- 2.27.0