From patchwork Thu Jan 19 21:22:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Edgecombe X-Patchwork-Id: 13108793 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 308B5C46467 for ; Thu, 19 Jan 2023 21:23:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DB5E6B0098; Thu, 19 Jan 2023 16:23:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4646F8E0001; Thu, 19 Jan 2023 16:23:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CCA16B009A; Thu, 19 Jan 2023 16:23:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 04CBA6B0098 for ; Thu, 19 Jan 2023 16:23:52 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CE1CC1A03B3 for ; Thu, 19 Jan 2023 21:23:51 +0000 (UTC) X-FDA: 80372825862.18.573DC14 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf27.hostedemail.com (Postfix) with ESMTP id CF4354001B for ; Thu, 19 Jan 2023 21:23:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m0PxXXnH; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674163430; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=StQkA6ot9FCk/YmAiAeLd46+t6/Gkl8n00cyZWXpPeQ=; b=dhyJcAge5k0mskrDMGl1IN4kylqgae0xss1r+uEQ/aWoTM3jpgP7f0VZJ4NmU9xbs2sMCE HV1PxW10TN1fBV6O717bDOV/BRv6HpVgMoIqKrL/aNVqbelmYPyDyDZgrT/LJc0lLFiNRd vmF1Ec444bLf6fW4xk6guRS+I8dFxG8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m0PxXXnH; spf=pass (imf27.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674163430; a=rsa-sha256; cv=none; b=NXkj58XTp+E73T9OVo0lcAuVktSPd8LI5fXdeB8wiiQxoqUwAXkuiL277tChET6HrcD92S DOs7n1fLk8HpZQ5FwE2OPvWppONJud8FEh3mxVERJbJzhzbCCsM9lD/df1chDBmqduqBkU jjveeBEu2UJW4ujPnQXkmCwpL8ntfAM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674163429; x=1705699429; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=G9eEBGmU/UnEJ+400J+VwekvQK2O1I9MsdKnAZAqxQw=; b=m0PxXXnHdB2SO/3ZC825Nxe8WMtIyL7iqfoEJMAPKnTJ4BFvkUDrnIwt u1V0CZeMmq2WQ6ZJx2oZ4gtbTstPJLiQmrLSqA9jEaGQ3f+s+m52bT5Ik cQvwSG3va6uE6MV2+t9t3hprxDAb0Tg8APDUPRY90wB2MGOMnNzDsrnh5 fZcYW9xtPbvzkMAg3O6OI403wDZ/zdVtU35FSPDI77D1zPWbhEilAfgKB jrk5JU0bq2NQwcDxgzRKj67WktKsaUPudRdplhTyBC+fbS2hv4IuBzuSX 5VZH6ZCjEmg45jvyZcP6L66DMku5ovDNdH+U0ZoR5Wvvgg4RZlezo8zSU Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="323119501" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="323119501" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:49 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="989139056" X-IronPort-AV: E=Sophos;i="5.97,230,1669104000"; d="scan'208";a="989139056" Received: from hossain3-mobl.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.252.128.187]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 13:23:47 -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 v5 15/39] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Thu, 19 Jan 2023 13:22:53 -0800 Message-Id: <20230119212317.8324-16-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230119212317.8324-1-rick.p.edgecombe@intel.com> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CF4354001B X-Stat-Signature: e3h471nwjmoqgbk6puwdyqdhzytdem5t X-Rspam-User: X-HE-Tag: 1674163429-641397 X-HE-Meta: U2FsdGVkX1+MCi9cO5oYiqZH+v7UAhnArj+CGCf7rI33KbXaTMy14iuuZ7/3pKYawijp8HcPOc6hozNO9SuWA9MemhCHNLhik4vUPKf/ZPAq1ZMN0lP4E8lABwcxOi2FaqXvCaXzdSe9hF6hK+KAVDe/g8Y62Q8Vnk3X+ABvRapd9LXRH+ZI1sf9ublJR/BLYJhSBB9AS2zqs1Hu/cWIxG9nEUizcXkFe5sGllOSXsWeiE7AzVpJwtzF4Avk67olvtNwm0UzaC6eyu1KIAu3MYeJGIjZvdY66xMTURTqZfPzs8Nfd4aGtP8yQNPzdwIs9e3Cqi1/KZTO+1yK6ORM2H3rbtSxW9Cte7lReLacdekVrWuZ3UFDBo3wLQlhW+PyuiwNk6KFWwtfBrVN+ktPaIzZrx9/XReoRt9q2m2Cdo4+Ii/mDd8nkK3yYRfSj4EpCcKpqftNmh8SBErwmrend6VX6bh8jlug0iN36qrcj2EyjJFAyiylS/+D+3agImGFsyH2nCDSkHDsFDdS0GkCxbzNiFXMWf3K398mIVa3IJHIfovGEzmsXw4zf7zWJKgipJPYjMc2s7GN9XvGKUIWMRHahJ6LsTnNTEBJW5P6jnyA9c5LxgESdOcGcayRz3KkpYO08FgnVPTdkbUmTj79hMiUCc3dLT3pc8L4TkqfbywVqz/hFHLtraw/gAOYIBcmfEiCRByrbCy8mH+xR7R3Zs0MX4oRGASQLQUHFUrUO3RPTUZvwxLCdZv9QfWU/a3pAuuiKKrGrc3PAYJ10IYLO+u7/KAkFh/E3ZhB+/Uw5sd8dLGIqR/d/UvG6uDVwV5SnXKbrvx6iH8YsV56ogZEvuvjWLPsOFNq53q7zBPJnYavqLjj08iiK6bLm4Rvb/GzXP3mM/WWvrJ91Bd8EPKkOe82NpVkcODVt2Vq/9WWwocCp/Fer8+EOM+EXKDuwY/zumzlbzXN20Z79SR7aOV tuBY39MZ /kQVoBWIxw6hPbcr0jVinL1/CPuaQi0wNmmjiDSRMCW4d/lF2JsN8CiSRsR8Sgw9ZBYMk08otvI+W3RujngjSaTm5YlOHbGAKp5pg9uCBoGZXc3mKKH25PhuRydsnDZcjg42GUEjfgrMGplAmh7yMYp2VZGhIlhDaGbfHdaIidzOujL36E0nGHcfS5sXLAs/ERC3W4JMMEjx+IQ+bDBgE7De1Htbc1hzQrwHiVyceVvJTHBaPsdMt3vQaVaZbtlsI4LEw4HlUq4bwx9JDiOjzyor1L378cHZr6rJtQMzzg1Sl87ztszNYFEyUJdd3DouvflNlds7/EI/BNdZ7u6nYjX/keA== 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: 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. Reviewed-by: Kees Cook 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 --- 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 e224b6d5b642..115843e8cce3 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -564,6 +564,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 e35a0398db63..982126ffdbae 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -711,6 +711,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 82a9a4903651..824e730b21af 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -315,11 +315,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 @@ -335,6 +337,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)