]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
x86/mm/pti: Introduce pti_finalize()
authorJoerg Roedel <jroedel@suse.de>
Wed, 18 Jul 2018 09:41:06 +0000 (11:41 +0200)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 1 Apr 2019 12:37:29 +0000 (14:37 +0200)
CVE-2017-5754

Introduce a new function to finalize the kernel mappings for the userspace
page-table after all ro/nx protections have been applied to the kernel
mappings.

Also move the call to pti_clone_kernel_text() to that function so that it
will run on 32 bit kernels too.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Pavel Machek <pavel@ucw.cz>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: linux-mm@kvack.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Laight <David.Laight@aculab.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Eduardo Valentin <eduval@amazon.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: aliguori@amazon.com
Cc: daniel.gruss@iaik.tugraz.at
Cc: hughd@google.com
Cc: keescook@google.com
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Waiman Long <llong@redhat.com>
Cc: "David H . Gutteridge" <dhgutteridge@sympatico.ca>
Cc: joro@8bytes.org
Link: https://lkml.kernel.org/r/1531906876-13451-30-git-send-email-joro@8bytes.org
(cherry picked from commit b976690f5db26fbc7c2be413bfa0fbd270547a94)
Signed-off-by: Juerg Haefliger <juergh@canonical.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tyler Hicks <tyhicks@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/x86/include/asm/pti.h
arch/x86/mm/init_64.c
arch/x86/mm/pti.c
include/linux/pti.h
init/main.c

index 38a17f1d5c9d674c86696cdd22f4a93b2116d4c0..5df09a0b80b801bcd6cc9adc780dec594d84ccad 100644 (file)
@@ -6,10 +6,9 @@
 #ifdef CONFIG_PAGE_TABLE_ISOLATION
 extern void pti_init(void);
 extern void pti_check_boottime_disable(void);
-extern void pti_clone_kernel_text(void);
+extern void pti_finalize(void);
 #else
 static inline void pti_check_boottime_disable(void) { }
-static inline void pti_clone_kernel_text(void) { }
 #endif
 
 #endif /* __ASSEMBLY__ */
index 52ecb739d30596aad4058a3e8c37f5cc03394b5a..5d8094995bb0ec3fa9ca4beaebb52b93a65cc596 100644 (file)
@@ -1280,12 +1280,6 @@ void mark_rodata_ro(void)
                        (unsigned long) __va(__pa_symbol(_sdata)));
 
        debug_checkwx();
-
-       /*
-        * Do this after all of the manipulation of the
-        * kernel text page tables are complete.
-        */
-       pti_clone_kernel_text();
 }
 
 int kern_addr_valid(unsigned long addr)
index 3b2995c4662c6a8b6a6cd2c0f2a16be0e2db0206..dfc545ced03333eba3b654615ddbc609463426ab 100644 (file)
@@ -463,7 +463,7 @@ static inline bool pti_kernel_image_global_ok(void)
  * For some configurations, map all of kernel text into the user page
  * tables.  This reduces TLB misses, especially on non-PCID systems.
  */
-void pti_clone_kernel_text(void)
+static void pti_clone_kernel_text(void)
 {
        /*
         * rodata is part of the kernel image and is normally
@@ -527,3 +527,15 @@ void __init pti_init(void)
        pti_setup_espfix64();
        pti_setup_vsyscall();
 }
+
+/*
+ * Finalize the kernel mappings in the userspace page-table.
+ */
+void pti_finalize(void)
+{
+       /*
+        * Do this after all of the manipulation of the
+        * kernel text page tables are complete.
+        */
+       pti_clone_kernel_text();
+}
index 0174883a935a25ddef6b33ad4765c65f0f3b25c4..1a941efcaa6223a55a8bfcceeb7fb798bbbb1bb4 100644 (file)
@@ -6,6 +6,7 @@
 #include <asm/pti.h>
 #else
 static inline void pti_init(void) { }
+static inline void pti_finalize(void) { }
 #endif
 
 #endif
index 44f88af9b191d5d3d3f285fbe1f2aae4699734e2..86189df2f34ad163bae6dbb66e8b2aa8ac996b05 100644 (file)
@@ -1009,6 +1009,13 @@ static int __ref kernel_init(void *unused)
        ftrace_free_init_mem();
        free_initmem();
        mark_readonly();
+
+       /*
+        * Kernel mappings are now finalized - update the userspace page-table
+        * to finalize PTI.
+        */
+       pti_finalize();
+
        system_state = SYSTEM_RUNNING;
        numa_default_policy();