[lkml]   [2018]   [Mar]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 4.9 086/177] x86/KASLR: Fix kexec kernel boot crash when KASLR randomization fails
4.9-stable review patch.  If anyone has any objections, please let me know.


From: Baoquan He <>

[ Upstream commit da63b6b20077469bd6bd96e07991ce145fc4fbc4 ]

Dave found that a kdump kernel with KASLR enabled will reset to the BIOS
immediately if physical randomization failed to find a new position for
the kernel. A kernel with the 'nokaslr' option works in this case.

The reason is that KASLR will install a new page table for the identity
mapping, while it missed building it for the original kernel location
if KASLR physical randomization fails.

This only happens in the kexec/kdump kernel, because the identity mapping
has been built for kexec/kdump in the 1st kernel for the whole memory by
calling init_pgtable(). Here if physical randomizaiton fails, it won't build
the identity mapping for the original area of the kernel but change to a
new page table '_pgtable'. Then the kernel will triple fault immediately
caused by no identity mappings.

The normal kernel won't see this bug, because it comes here via startup_32()
and CR3 will be set to _pgtable already. In startup_32() the identity
mapping is built for the 0~4G area. In KASLR we just append to the existing
area instead of entirely overwriting it for on-demand identity mapping
building. So the identity mapping for the original area of kernel is still

To fix it we just switch to the new identity mapping page table when physical
KASLR succeeds. Otherwise we keep the old page table unchanged just like
"nokaslr" does.

Signed-off-by: Baoquan He <>
Signed-off-by: Dave Young <>
Acked-by: Kees Cook <>
Cc: Borislav Petkov <>
Cc: Dave Jiang <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Garnier <>
Cc: Thomas Gleixner <>
Cc: Yinghai Lu <>
Signed-off-by: Ingo Molnar <>
Signed-off-by: Sasha Levin <>
Signed-off-by: Greg Kroah-Hartman <>
arch/x86/boot/compressed/kaslr.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -460,10 +460,17 @@ void choose_random_location(unsigned lon
add_identity_map(random_addr, output_size);
*output = random_addr;
+ /*
+ * This loads the identity mapping page table.
+ * This should only be done if a new physical address
+ * is found for the kernel, otherwise we should keep
+ * the old page table to make it be like the "nokaslr"
+ * case.
+ */
+ finalize_identity_maps();

- /* This actually loads the identity pagetable on x86_64. */
- finalize_identity_maps();

/* Pick random virtual address starting from LOAD_PHYSICAL_ADDR. */

 \ /
  Last update: 2018-03-23 12:24    [W:0.728 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site