From patchwork Sat Feb 18 21:14:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13145657 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 48C84C64ED9 for ; Sat, 18 Feb 2023 21:16:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBF1828000F; Sat, 18 Feb 2023 16:16:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D841028000D; Sat, 18 Feb 2023 16:16:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C18D0280011; Sat, 18 Feb 2023 16:16:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AB24F28000D for ; Sat, 18 Feb 2023 16:16:17 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8223FAAD8B for ; Sat, 18 Feb 2023 21:16:17 +0000 (UTC) X-FDA: 80481670794.03.33E9D8C Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf16.hostedemail.com (Postfix) with ESMTP id 84272180004 for ; Sat, 18 Feb 2023 21:16:15 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=n3sEmWyd; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 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=1676754975; 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=hZVQOPh5gsC4utlFQ0Ct33FH6ZCu3J+LIAtvRyiL4EQ=; b=nYwpeNIskFsRll/3gtSHWXbGWPVMV4NPVJrhOF39c8ZoRxqFkz2J5h6VcJJXUdG3Q2uzZ6 tA/iQtkW0dHf3ePef04zzPephb0kAErnxCEQ5indv+F0Sblzhsh1Ax7dIR3gdun40fnFEP drpRGlmI0uLXTEkZIcC7bC7EUfOCnb8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=n3sEmWyd; spf=pass (imf16.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.43 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=1676754975; a=rsa-sha256; cv=none; b=sukGcFSpo4z4uvSMr2vayY84MEk3quoKz9pjUj28PY50jdW0WFqh7+nhklckROrBOKPR3O k60g6DTox/1orXoXpbR1BXSu1mfl59Pfl/qMR6VbEX8YyclHIcRasY2gangWPekYex7Q7Q 5jaOGn3t/B1aSAP3qqro6GHvrsxOrkA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676754975; x=1708290975; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=tPsImO1U6ZzFWnTQpJpFZiSIEfl+QZcqM1Ze+IYBtwc=; b=n3sEmWydaK6VZhhGULwuc/bc1qbXgbYBXiPewvkBF/9dUWqT5/vLF1Mx c0TN4HDxdaz+W0yATGz0GjXpRRRHQ68zAfGPOBBvJ8LKmBswHg0QYNRGN zkFg3Mt5pyhf2/yes8Bbyvw0kZdMQ93+Adnm9EKiWBYfFtPB2nf940ocR DvGkAzVaRN/aW1Fsmz7WNkOay6dZbRd36ggitgZdFcWXK9BRtpXPeQ99T ojMEeg5yEmOKIjUAbywC51epHpMoGa0n+Sko8+bQ2/88Yf4KiTDfurj47 TpzwTAd2WZlhSqklg3d3jHrXw3oETED8OOwiZ9hw9ys3h2Ks4f1SfSoaR Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="418427485" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="418427485" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:11 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10625"; a="664241659" X-IronPort-AV: E=Sophos;i="5.97,309,1669104000"; d="scan'208";a="664241659" Received: from adityava-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.80.223]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2023 13:16:10 -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, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v6 18/41] mm: Introduce VM_SHADOW_STACK for shadow stack memory Date: Sat, 18 Feb 2023 13:14:10 -0800 Message-Id: <20230218211433.26859-19-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230218211433.26859-1-rick.p.edgecombe@intel.com> References: <20230218211433.26859-1-rick.p.edgecombe@intel.com> X-Rspamd-Queue-Id: 84272180004 X-Stat-Signature: rp1su1hyx6b6w8cghsxdju6ywk9a13qy X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676754975-827273 X-HE-Meta: U2FsdGVkX1/BfOFFS4KKYmeuH4nqPOcTHHhFjh8zKQQrGRk7gSVn4KmtntUSw57zm/5ThzYXHrLUGzaqZoGL+KZ4e7+lmJNkXz5w82yC/4S7lml/xfrz6wXdactawv+Q4NNJ/CcTc4nKFNkGaXn+ap2mpZ63fhpZA5ws/v7ayVDPzk3RFeG4yKiOO3XpotXm08V/p0w/xy6V8ZZqA8OckV3Jf6VjnF5Vj6/dTIntOSfwcs52vGL8sybrqVoMVGdk0+H3xVtKLgxBKGqEQWOUiAK/lK4JAue4iHpPAlGzKloIrsBbm1nsoqLS3Vl1T8mMKLXPWcm//+9bBQ4Xzik6a80QDY6RYT6JeJKljW5VQSQ8Pb0Sn7eSQBLJz9EDgpnAcFhiCbfzKp+rt+0fViRL5i2AV2VJU5MMuRzplT1/VN1AAejNuEXAcDMiWD69Jqp2c317trgj95/hNCZNfFc8IwK7g4QJoPW4mJhHJ+/IsnFdayQ8oYXbJrwlErbB2wnaJXQZZ58W9K/FoAv2ylb3EmTaOIUr7UR6+Fc4JsU10GoUgej41x8ZJRHHKtWEIa2T/Qhvr4cQrYA53YrITk46nkeEQ7qort2hVhMDOBf/4RwghVMN+VMI3HZZ2F8cTkRqMdKCncuHRnrNuLtLMQ55mvtNeB0zv75WeC7GqJrn6icZ+SoLXrY2MNUEjOXSH/k75sCYWgcn/Pt+iwCxgL7a9tMqAgxgm3CakDf6O3OyswaWq4hp3z9+CEfbs7/lxZpIj0h6lkgt6JaEUTkfTseVTSeMCVX9NwUzWh/0snVVq/zwZdZKOajWv+Fyt+Iq/2fd0fRFy+Ybqbym7DRU77GEMNdEE8BvJ3qMWqeu/lbh1EkBeuk5RfbKpuN6e4xyiEMjVeCCVLqtzgNDoUgH3Xy0R7jmA5oGvYjWxzSA4sZ2QfRwZastHT9XVJpyrj9gqtWks+yg4Eurn2k4ZVIEzF3 GVeJCxVJ +7CMcC7XenaYbdF5NXDlwTFyDhKbf6M+F7KkzeHg/UZtrIu2gmcEVhod6hbOGc1l6leyfRgXrg5EttXPZs7GF9JsEAAJu69IwDpxltI1UOavZd/3DJOuATwxF90lEbbIgLHx6dzLw2LZHbPfsRLU7JmoSug04y+fWfSfzMDPtHyoXkSNKtXvRsEMX5EMAmxnqOo11TosxhsljnLBH52QCJuyNC1po2BrkO7WM8awE0P4S0yr7pHQds01OIauTSLWiWDncLL1PsktYNkcc4VYAlMEKaz1elMGCwS28ugTbi7gUTXqAC0O0Fxqvxm5pg2SJswOc2QJ+IookkvU= 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 Acked-by: David Hildenbrand --- v6: - Add comment about VM_SHADOW_STACK not being allowed with VM_SHARED (David Hildenbrand) 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 af1c49ae11b1..9e2cefe47749 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 e6f1789c8e69..76e0a09aeffe 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 /* 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)