From patchwork Wed Jul 19 22:47:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 122909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2771070vqt; Wed, 19 Jul 2023 16:26:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqYdpbXqx5Vp57LdexuzgADFyKu1DKLt4mexy82XahtSY3HW3kN/dgwKNa53SU3gyuOVdd X-Received: by 2002:a05:620a:398d:b0:768:1e8d:67fb with SMTP id ro13-20020a05620a398d00b007681e8d67fbmr914818qkn.74.1689809205803; Wed, 19 Jul 2023 16:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689809205; cv=none; d=google.com; s=arc-20160816; b=EbzSit44jTkfU9eO/6xcewP3H96NLs9Uv/yxF03/VAJkrQpYlWp/vnXmO3kTCYq9DT sRpmIbK+yZpoODmG4+U/pGA2LxYjpp/ot0t5mpdfFZQjq3cDP8aiu0fz2sdg+eBgvi9j C1sL5HzOKX2B/UjvUYtJ+Yifots4mQS3Ays0TJ7I9WjMWvj6V4otWr5dE3m5l47GjgnS 45XNKBP6PJnmPQvIpN8RZRLvhI7xfnq9fPO5BHMHEzi8KLwVkP4WdAP34llqT6m36OAt oHqEbSl+C6XfzJ3JXJ8MOYKCD3dXHi2D9/zAdL4UkyJYXSXU+O9FdqFGRuesOYiB9NvI LvAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=505CqrebyxmLIvSosX+gV1/TrhgvI1azWm/Zpa2HFww=; fh=fxr/lnVgB8dq9hf2VWQXcFyfIfk+jDNX5GrHaNBVAz0=; b=ANgoJGQOdpxLs+VDDVRyP8iY6d59WQTZYCRdQinsws+mF/OHH+yy1PHNaIt6M9mIxw t/023fERWx66+je/qo4/b5w0SDXkd+Ktrn30AEtFw6fTc1VWzhh7UpJMK52xxMDzrK3t oO5Sh3XCG0gQ+gjvZQcwgFRVDaXUi//02IrsoEQxVDkbdoClxPAJyvf7gQ8lL9rBpusR gRQ0ZKNwRnWAgXOC5oC2prJJRLAqztqUSk8LiaAQqaTHENvXlyDfz+sRXCCxUHAy3Suh ls3bNGzdJd3Zz+h8hcmd+hYH2DGFBCpfvVDSjltCVP9gAct1LRwMYYQBkji9C1L7iv3F Kfsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=owAq5oiY; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i10-20020a17090acf8a00b00262ffca5a31si2236047pju.161.2023.07.19.16.26.33; Wed, 19 Jul 2023 16:26:45 -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=@linutronix.de header.s=2020 header.b=owAq5oiY; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbjGSWtV (ORCPT + 99 others); Wed, 19 Jul 2023 18:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231207AbjGSWrx (ORCPT ); Wed, 19 Jul 2023 18:47:53 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBB8626AB; Wed, 19 Jul 2023 15:47:40 -0700 (PDT) Date: Wed, 19 Jul 2023 22:47:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689806858; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=505CqrebyxmLIvSosX+gV1/TrhgvI1azWm/Zpa2HFww=; b=owAq5oiYB3N3kSKW7qlbAgGEvx8pl947KQq74b4vCq/+NfQZ68PD9DQ85Q8dFRdEgQd9+7 rYbWDmc9yhkmeIRg58GZbvW970bAoZ3HRJU+t5TpSVi2hgoYowWPV/tWJaBfYSN9Y13vPK ox5yS2dswYPxh8J6hVpx8Clg1MZosJXQ6ydCWqy7TiS2ziB3GjfJg4fQC1e0B/8KE6/W95 D0QvzR8HZH80iZC23jJkZ9/mFQ6JJZbPiI7i3aYP+77/BabvvH0qnW8tOYiLSp3TeBvlCT rl+TesjtO9KJDwGTZPcwUldoqVxBaI/zYdwBlMbwlftsMV0Nl9DW8AurFybBtg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689806858; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=505CqrebyxmLIvSosX+gV1/TrhgvI1azWm/Zpa2HFww=; b=LlN9XtI7jGlyNSZUAlrPAeon8A1bowRuBljGr6SlwlIU0jZxtDXNnXGcpBCH9ZK5TmdW/T srISDoF8012hfwDQ== From: "tip-bot2 for Yu-cheng Yu" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] mm: Introduce VM_SHADOW_STACK for shadow stack memory Cc: "Yu-cheng Yu" , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , "Kirill A. Shutemov" , Mark Brown , "Mike Rapoport (IBM)" , David Hildenbrand , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168980685807.28540.4175493079802645829.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771893377725295764 X-GMAIL-MSGID: 1771893377725295764 The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 54007f818206dc27309ca423df4c87dd160a7208 Gitweb: https://git.kernel.org/tip/54007f818206dc27309ca423df4c87dd160a7208 Author: Yu-cheng Yu AuthorDate: Mon, 12 Jun 2023 17:10:40 -07:00 Committer: Rick Edgecombe CommitterDate: Tue, 11 Jul 2023 14:12:19 -07:00 mm: Introduce VM_SHADOW_STACK for shadow stack memory New hardware extensions implement support for shadow stack memory, such as x86 Control-flow Enforcement Technology (CET). Add a new VM flag to identify these areas, for example, to be used to properly indicate shadow stack PTEs to the hardware. Shadow stack VMA creation will be tightly controlled and limited to anonymous memory to make the implementation simpler and since that is all that is required. The solution will rely on pte_mkwrite() to create the shadow stack PTEs, so it will not be required for vm_get_page_prot() to learn how to create shadow stack memory. For this reason document that VM_SHADOW_STACK should not be mixed with VM_SHARED. Co-developed-by: Rick Edgecombe 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 Reviewed-by: Kirill A. Shutemov Reviewed-by: Mark Brown Acked-by: Mike Rapoport (IBM) Acked-by: David Hildenbrand Tested-by: Mark Brown Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230613001108.3040476-15-rick.p.edgecombe%40intel.com --- Documentation/filesystems/proc.rst | 1 + fs/proc/task_mmu.c | 3 +++ include/linux/mm.h | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 7897a7d..6ccb570 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -566,6 +566,7 @@ encoded manner. The codes are the following: mt arm64 MTE allocation tags are enabled um userfaultfd missing tracking uw userfaultfd wr-protect tracking + ss shadow stack page == ======================================= Note that there is no guarantee that every flag and associated mnemonic will diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 507cd4e..cfab855 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -709,6 +709,9 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR [ilog2(VM_UFFD_MINOR)] = "ui", #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ +#ifdef CONFIG_X86_USER_SHADOW_STACK + [ilog2(VM_SHADOW_STACK)] = "ss", +#endif }; size_t i; diff --git a/include/linux/mm.h b/include/linux/mm.h index 82990f3..f6c2ebd 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -319,11 +319,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */ +#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0) #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1) #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2) #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3) #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) +#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5) #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #ifdef CONFIG_ARCH_HAS_PKEYS @@ -339,6 +341,12 @@ extern unsigned int kobjsize(const void *objp); #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ +#ifdef CONFIG_X86_USER_SHADOW_STACK +# define VM_SHADOW_STACK VM_HIGH_ARCH_5 /* Should not be set with VM_SHARED */ +#else +# define VM_SHADOW_STACK VM_NONE +#endif + #if defined(CONFIG_X86) # define VM_PAT VM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ #elif defined(CONFIG_PPC)