]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0193-x86-mm-pti-Allow-NX-poison-to-be-set-in-p4d-pgd.patch
KPTI: add follow-up fixes
[pve-kernel.git] / patches / kernel / 0193-x86-mm-pti-Allow-NX-poison-to-be-set-in-p4d-pgd.patch
CommitLineData
321d628a
FG
1From ea96d1e71945047c9e0af526e68b18782acc12c4 Mon Sep 17 00:00:00 2001
2From: Dave Hansen <dave.hansen@linux.intel.com>
3Date: Mon, 4 Dec 2017 15:07:38 +0100
e4cdf2a5 4Subject: [PATCH 193/241] x86/mm/pti: Allow NX poison to be set in p4d/pgd
321d628a
FG
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9CVE-2017-5754
10
11With PAGE_TABLE_ISOLATION the user portion of the kernel page tables is
12poisoned with the NX bit so if the entry code exits with the kernel page
13tables selected in CR3, userspace crashes.
14
15But doing so trips the p4d/pgd_bad() checks. Make sure it does not do
16that.
17
18Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
19Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
20Reviewed-by: Borislav Petkov <bp@suse.de>
21Cc: Andy Lutomirski <luto@kernel.org>
22Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
23Cc: Borislav Petkov <bp@alien8.de>
24Cc: Brian Gerst <brgerst@gmail.com>
25Cc: David Laight <David.Laight@aculab.com>
26Cc: Denys Vlasenko <dvlasenk@redhat.com>
27Cc: Eduardo Valentin <eduval@amazon.com>
28Cc: Greg KH <gregkh@linuxfoundation.org>
29Cc: H. Peter Anvin <hpa@zytor.com>
30Cc: Josh Poimboeuf <jpoimboe@redhat.com>
31Cc: Juergen Gross <jgross@suse.com>
32Cc: Linus Torvalds <torvalds@linux-foundation.org>
33Cc: Peter Zijlstra <peterz@infradead.org>
34Cc: Will Deacon <will.deacon@arm.com>
35Cc: aliguori@amazon.com
36Cc: daniel.gruss@iaik.tugraz.at
37Cc: hughd@google.com
38Cc: keescook@google.com
39Cc: linux-kernel@vger.kernel.org
40Signed-off-by: Ingo Molnar <mingo@kernel.org>
41(cherry picked from commit 1c4de1ff4fe50453b968579ee86fac3da80dd783)
42Signed-off-by: Andy Whitcroft <apw@canonical.com>
43Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
44(cherry picked from commit 889a8bd0e57e39e7ce337e87c55fa59c09644d4e)
45Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
46---
47 arch/x86/include/asm/pgtable.h | 14 ++++++++++++--
48 1 file changed, 12 insertions(+), 2 deletions(-)
49
50diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
51index abbb47c75467..3ef8415b2358 100644
52--- a/arch/x86/include/asm/pgtable.h
53+++ b/arch/x86/include/asm/pgtable.h
54@@ -831,7 +831,12 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
55
56 static inline int p4d_bad(p4d_t p4d)
57 {
58- return (p4d_flags(p4d) & ~(_KERNPG_TABLE | _PAGE_USER)) != 0;
59+ unsigned long ignore_flags = _KERNPG_TABLE | _PAGE_USER;
60+
61+ if (IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION))
62+ ignore_flags |= _PAGE_NX;
63+
64+ return (p4d_flags(p4d) & ~ignore_flags) != 0;
65 }
66 #endif /* CONFIG_PGTABLE_LEVELS > 3 */
67
68@@ -865,7 +870,12 @@ static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
69
70 static inline int pgd_bad(pgd_t pgd)
71 {
72- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
73+ unsigned long ignore_flags = _PAGE_USER;
74+
75+ if (IS_ENABLED(CONFIG_PAGE_TABLE_ISOLATION))
76+ ignore_flags |= _PAGE_NX;
77+
78+ return (pgd_flags(pgd) & ~ignore_flags) != _KERNPG_TABLE;
79 }
80
81 static inline int pgd_none(pgd_t pgd)
82--
832.14.2
84