]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0190-x86-mm-pti-Disable-global-pages-if-PAGE_TABLE_ISOLAT.patch
add tc fixes
[pve-kernel.git] / patches / kernel / 0190-x86-mm-pti-Disable-global-pages-if-PAGE_TABLE_ISOLAT.patch
CommitLineData
59d5af67 1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
321d628a
FG
2From: Dave Hansen <dave.hansen@linux.intel.com>
3Date: Mon, 4 Dec 2017 15:07:34 +0100
59d5af67 4Subject: [PATCH] x86/mm/pti: Disable global pages if PAGE_TABLE_ISOLATION=y
321d628a
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9CVE-2017-5754
10
11Global pages stay in the TLB across context switches. Since all contexts
12share the same kernel mapping, these mappings are marked as global pages
13so kernel entries in the TLB are not flushed out on a context switch.
14
15But, even having these entries in the TLB opens up something that an
16attacker can use, such as the double-page-fault attack:
17
18 http://www.ieee-security.org/TC/SP2013/papers/4977a191.pdf
19
20That means that even when PAGE_TABLE_ISOLATION switches page tables
21on return to user space the global pages would stay in the TLB cache.
22
23Disable global pages so that kernel TLB entries can be flushed before
24returning to user space. This way, all accesses to kernel addresses from
25userspace result in a TLB miss independent of the existence of a kernel
26mapping.
27
28Suppress global pages via the __supported_pte_mask. The user space
29mappings set PAGE_GLOBAL for the minimal kernel mappings which are
30required for entry/exit. These mappings are set up manually so the
31filtering does not take place.
32
33[ The __supported_pte_mask simplification was written by Thomas Gleixner. ]
34Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
35Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
36Reviewed-by: Borislav Petkov <bp@suse.de>
37Cc: Andy Lutomirski <luto@kernel.org>
38Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
39Cc: Borislav Petkov <bp@alien8.de>
40Cc: Brian Gerst <brgerst@gmail.com>
41Cc: David Laight <David.Laight@aculab.com>
42Cc: Denys Vlasenko <dvlasenk@redhat.com>
43Cc: Eduardo Valentin <eduval@amazon.com>
44Cc: Greg KH <gregkh@linuxfoundation.org>
45Cc: H. Peter Anvin <hpa@zytor.com>
46Cc: Josh Poimboeuf <jpoimboe@redhat.com>
47Cc: Juergen Gross <jgross@suse.com>
48Cc: Linus Torvalds <torvalds@linux-foundation.org>
49Cc: Peter Zijlstra <peterz@infradead.org>
50Cc: Will Deacon <will.deacon@arm.com>
51Cc: aliguori@amazon.com
52Cc: daniel.gruss@iaik.tugraz.at
53Cc: hughd@google.com
54Cc: keescook@google.com
55Cc: linux-mm@kvack.org
56Signed-off-by: Ingo Molnar <mingo@kernel.org>
57(cherry picked from commit c313ec66317d421fb5768d78c56abed2dc862264)
58Signed-off-by: Andy Whitcroft <apw@canonical.com>
59Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
60(cherry picked from commit ace78e99d765da1e59f6b151adac6c360c67af7d)
61Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
62---
63 arch/x86/mm/init.c | 12 +++++++++---
64 1 file changed, 9 insertions(+), 3 deletions(-)
65
66diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
67index a22c2b95e513..020223420308 100644
68--- a/arch/x86/mm/init.c
69+++ b/arch/x86/mm/init.c
70@@ -161,6 +161,12 @@ struct map_range {
71
72 static int page_size_mask;
73
74+static void enable_global_pages(void)
75+{
76+ if (!static_cpu_has(X86_FEATURE_PTI))
77+ __supported_pte_mask |= _PAGE_GLOBAL;
78+}
79+
80 static void __init probe_page_size_mask(void)
81 {
82 /*
83@@ -179,11 +185,11 @@ static void __init probe_page_size_mask(void)
84 cr4_set_bits_and_update_boot(X86_CR4_PSE);
85
86 /* Enable PGE if available */
87+ __supported_pte_mask &= ~_PAGE_GLOBAL;
88 if (boot_cpu_has(X86_FEATURE_PGE)) {
89 cr4_set_bits_and_update_boot(X86_CR4_PGE);
90- __supported_pte_mask |= _PAGE_GLOBAL;
91- } else
92- __supported_pte_mask &= ~_PAGE_GLOBAL;
93+ enable_global_pages();
94+ }
95
96 /* Enable 1 GB linear kernel mappings if available: */
97 if (direct_gbpages && boot_cpu_has(X86_FEATURE_GBPAGES)) {
98--
992.14.2
100