From patchwork Tue Jun 13 00:10:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13277721 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 DEDA6C7EE43 for ; Tue, 13 Jun 2023 00:12:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 008178E0007; Mon, 12 Jun 2023 20:12:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7DB8E0003; Mon, 12 Jun 2023 20:12:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFCC38E0008; Mon, 12 Jun 2023 20:12:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B8DE68E0003 for ; Mon, 12 Jun 2023 20:12:16 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 71307C034E for ; Tue, 13 Jun 2023 00:12:16 +0000 (UTC) X-FDA: 80895797472.26.2F685F0 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf19.hostedemail.com (Postfix) with ESMTP id 606561A0004 for ; Tue, 13 Jun 2023 00:12:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=J5dsVrvs; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf19.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 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=1686615134; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ryAUT3UXrAcsGxsWLBFRJE1PqULflYsxnmjTi3z/Wrs=; b=A+pG4f7xGZiupHruGMdVjiuynSy95t7tTWviOoMPfKCpSOUiOtIxHRBidxRB1MMXofhvfW /yCN6MF5piARUVe/hBEKVUYXnH0W96N9UbDSPwmiL/2rQdm2pNrP66bHE3i0n/Md48kx5b MIcun9o1wJdseFKH3alr03e8Ja3heFk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=J5dsVrvs; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf19.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686615134; a=rsa-sha256; cv=none; b=L4tIlVNoSAtNVEUUytoG15ZnZKkNKIAbZpy+2PyawdfoNKPlexHMqA4xN6T9zqT46BE3v+ Lkj5arWUc051uwJmr3u9Stoyzh8g/617FkQnMG0NyPfvxDZrshC3uEv3vTRG7l6+If3Re0 op/hWU/ObsI3Vkcu24xq9TmnkZpmSjw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686615134; x=1718151134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VIRIy8IvN5ZfY5u3MVh2ThurjhiZOJC7RcXup7TqiYM=; b=J5dsVrvsQoEiGXjU2/F2mZxHX9Wtgd8eR1tZAx8sTiWaU7g0Nl12dqYK WC3qIDwv9pTqoHO0SUKRtQbFVgJJXVmXRdQq776vDZ4XBTtUinn7yXkpX ERI5enbupURzIofkxsAzQJggymoC2YwNLTDDS+h4d2p1nfMoSJCBZc/Kg eavVqt6vEYuEaRlEVK9WIqidIFBhMoFKjW197xXJdbTN5Yq4FpZ4taULP CCWpLI0rtXeHOqMTe1e4WkxVbWxAAihvoerV/Tg1OhCah5+fCvni+h7rs 76q2oZ2nMw/rCfj7YwiGzBlGan0ehh2rHw5r0hr9f0ABIGqfzZ0iSoLJv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="361556785" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="361556785" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10739"; a="835670988" X-IronPort-AV: E=Sophos;i="6.00,238,1681196400"; d="scan'208";a="835670988" Received: from almeisch-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.amr.corp.intel.com) ([10.209.42.242]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2023 17:12:10 -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, torvalds@linux-foundation.org, broonie@kernel.org Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu , Pengfei Xu Subject: [PATCH v9 06/42] x86/shstk: Add Kconfig option for shadow stack Date: Mon, 12 Jun 2023 17:10:32 -0700 Message-Id: <20230613001108.3040476-7-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> References: <20230613001108.3040476-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 606561A0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 8ykrsc19utb6rzx4wakd7j1rdk6z9f7z X-HE-Tag: 1686615134-513816 X-HE-Meta: U2FsdGVkX1/o6muee5ISm98l2mLK8dol8QWBRcPXtSVqOY141Um9RcIysGVxuene/rMobZ4z0QqvuOB1mKt4U9VQMha5QfqD+pLcnKUGjAFgflfnSUUF7wjrp5SHU/QeATHogJUepMPAtwI+s35QZTQpStJOca2MdGojaxhbWztPi6X7beUYMwaj3MZcW6g5mbzY0GA/DfZSqwgisgWSu8GhpdW1fuIFdj7fknhcZZsaPFC5wlLhZc8R3/MwY2g/S0FADLfCQuuv0s8HcSjjyG6SeeLCpOD2rEcT7hXuL7docQJEk4BlxmTv46uTe2qqdA299bDKlZO4nujwpducfZLVbRgS9R6A7XrMd0W2M6VDEx4a6amOoO+4EfQZ/h0Jxoilyh0XZc5fjIWCR3VnEKEAR0o+SfjrIqySzikl+3FjmpfvlLnooeMv7GvOyylpLvDaLxmEMyPMaKaMcHrW7gQcMQpM9rRmANAYwsiZbjxGUatZIUMNE+glM6bzrl/VzYkfwaLlbs12Lr5aO5m4i0gBsN3IFfu6Vqk6gD8iy3G2uNn4CTYvNYcCa2IeH4QkmcVRx/f7Wv/30V+M2rljA8UuKYbhnfvb5JRQBxT26An0INFJmix8sWZb/pFsEKB2YMQx06TEeuJPeprYX0hiAFTghkQ2HCOz3kbWllfHvL3B2IGm2KrmLi/tlizd9wlzLaYD8yTMy1QTmirxrZNTLEK0Aw0kK2m3Fo2umIHrzBIZGqvvsE+K9LzD8hRpjJ6DdXcFrseTi6LvT6ZMxs8Gpe3umajwiomU8yN9HX1UMRr+CNjG9V3duoagxV385QKrN7OFVYQfo5GDJOXBF2IMtNjzU6K7hW5VLU2VvUr7dh/7oFCLiUnkqApDYWEtAJNeYNOTzovkEenIizX8+1xF9p+qWQE/q6F5HEmOuMrUS/6nFKhjoKTyPpQkskacLv9hgLQc9SdCMsjSztu/cRg ot6ynY+T GT8iRDzGz5F3PYZCmdPOn7n9kKLyhczHhY9xmUTS5aW6sZIpYPdWgk5jGcBEncKeM6ISs9L/ZVHPaSMj2J/qAUvSNTRVdKdwknE720/uATfzbr5XulAlfPkh2jVRNe89+idNHRJhmC1isWHZfSchAhVTZlzvlxfNiHaBfsinHHcrF3Koa8z3FfQo32P0aRekgKdJlREvc0X7uiJAG9Xm1T11pPpgT3BXt5WwRzX68pKRC9JEjRHlu3UJVw3zjJH/V8xyKrm/eR2fvwrGIxUIZ8/aBbSQRcu4ODQY0vdxv8d627PWLA2OW7ona0UvSZ7cy21R14vJinZ9jKEqSxNW1rFy5r/b5bxGqdeLpfGfH/Z1PgQn/i5+iH2iqBfFRmwMUmNBsDI4crZx8qBI= 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: 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: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook --- 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 53bab123a8ee..ce460d6b4e25 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1852,6 +1852,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 @@ -1859,6 +1864,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