From patchwork Sat Dec 3 00:35:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 29173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1142422wrr; Fri, 2 Dec 2022 16:40:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5thWGf31E00xfRyb+Bg16YG5yIHgpkH5WdfS+nPfzQCeGLNo2j8M5xkXNuWm9emEqbHe6f X-Received: by 2002:a17:906:5050:b0:7b2:8f2c:a877 with SMTP id e16-20020a170906505000b007b28f2ca877mr36090179ejk.90.1670028048561; Fri, 02 Dec 2022 16:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670028048; cv=none; d=google.com; s=arc-20160816; b=IOkhyqnwqLQJCmbrGsnN84pc2OMRxpVIcuY02JC1/onH0N99lc/MMVuLlQ2/Hk3ZnR JmWLeV9DCdgX/TssBIstMfmqcq7Enga14++m+m0z6HrS7Ld+QMG8B0yJvepnsbjcvtGU LSlSSgSZ4thX2xfBGKhrzXPE7ctkczqpJbk7UBWO9NdiDmlEaaH6mRJGVnM/Vi1jzyUJ scsJVWJtjm+79i5cftZCeLpu75fUMTPv3Zl0taFBEgD04LKh+iIuZ2eIVyrCOvhMwlkD s61ou5qEK6jhRctl9WzhCRA6W7Q/7easjJLRLjwawkFBlYoLpyVOxgRFCYxKgx6lxqBd Oksw== 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=82MbcTbPfeyGqiJELrxIo7/pGq6Lnw3gQQiXTZFdsgM=; b=BniSGYL+SYU6iyH46p+FCW5cdIU22b6gzExPV0Ulg32wIVhNzGoLInUd9Z3PmhFYg2 WJhCBc6H+U1hxZBk6i2CkPirjG5Ajw6p2JCUECds8dtI404p+NRHx5YUDLlFWy0CtiGt BpK8txN9eBW2sH/eZt3ySNRGH9E1suVJpHpaCH9UTEK3WbA0db8n8+rGNXenY8hXAMGQ myGxwrBAhbpFsToClBpx+37BebVo4k3izGwLOUkIy7rLvJ17oLhFJAMaLV4D9t8jE8ju qbR1t3Z4SpP7/ZVpVzahaD7sbr1tmNUG4Lm68PS9W7oDz48SHzzWW5tPswigYeLqmBrn WMTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ql96+Beg; 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 bo28-20020a0564020b3c00b0046b807c1a03si1524621edb.77.2022.12.02.16.40.25; Fri, 02 Dec 2022 16:40:48 -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=Ql96+Beg; 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 S235161AbiLCAjU (ORCPT + 99 others); Fri, 2 Dec 2022 19:39:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235020AbiLCAib (ORCPT ); Fri, 2 Dec 2022 19:38:31 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B881FC2BB; Fri, 2 Dec 2022 16:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670027834; x=1701563834; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=/8ygfG70rYB7SEC4SbN3orD5L3ZmTAS2ypn+csy1744=; b=Ql96+BegosplW52c00P7hjzptjjiv90ulfuDWJBg0CFGq1VeuprcR+be nW2IT3TSo1+bVP3YTaBeWHX2BtW7wFEmZ3ANIrlRVr7E69v8SFmwYMweh Ot7Pfp78GhBv47Z7QQ4GiiVsjD/1XkKuqbtlmD5f4nig4Ufw70T4ken67 XeCf7wFGTq2gcp2s0i2qxxqfxiKgA+HCpzwULdHNSl2O2vdLiML5UpBXG EfynPrY0JtjTzomHzF5WYmBjzWPcCQrC2aup3CExk16Y2eHl7ViRGDiK9 eLy4TNz4BXbBYKk1rY1dDCCgZFyMmum1cc0So2cr88wZSCyDYL7txquR/ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="313711017" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="313711017" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 16:37:07 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10549"; a="787479877" X-IronPort-AV: E=Sophos;i="5.96,213,1665471600"; d="scan'208";a="787479877" Received: from bgordon1-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.212.211.211]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2022 16:37:04 -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 Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v4 15/39] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Fri, 2 Dec 2022 16:35:42 -0800 Message-Id: <20221203003606.6838-16-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221203003606.6838-1-rick.p.edgecombe@intel.com> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1751151330964225575?= X-GMAIL-MSGID: =?utf-8?q?1751151330964225575?= From: Yu-cheng Yu The x86 Control-flow Enforcement Technology (CET) feature includes a new type of memory called shadow stack. This shadow stack memory has some unusual properties, which requires some core mm changes to function properly. A shadow stack PTE must be read-only and have _PAGE_DIRTY set. However, read-only and Dirty PTEs also exist for copy-on-write (COW) pages. These two cases are handled differently for page faults. Introduce VM_SHADOW_STACK to track shadow stack VMAs. Tested-by: Pengfei Xu Tested-by: John Allen Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe Cc: Kees Cook Reviewed-by: Kees Cook --- v3: - Drop arch specific change in arch_vma_name(). The memory can show as anonymous (Kirill) - Change CONFIG_ARCH_HAS_SHADOW_STACK to CONFIG_X86_USER_SHADOW_STACK in show_smap_vma_flags() (Boris) 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 898c99eae8e4..05506dfa0480 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -560,6 +560,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 fa3eea895210..9c17502e9746 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -703,6 +703,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 9ae6bc38d0b7..b982c2749e7b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -303,11 +303,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 @@ -323,6 +325,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 +#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)