]> git.baikalelectronics.ru Git - kernel.git/commitdiff
x86/boot/KASLR: Fix kexec crash due to 'virt_addr' calculation bug
authorBaoquan He <bhe@redhat.com>
Tue, 27 Jun 2017 12:39:06 +0000 (20:39 +0800)
committerIngo Molnar <mingo@kernel.org>
Fri, 30 Jun 2017 06:53:14 +0000 (08:53 +0200)
Kernel text KASLR is separated into physical address and virtual
address randomization. And for virtual address randomization, we
only randomiza to get an offset between 16M and KERNEL_IMAGE_SIZE.
So the initial value of 'virt_addr' should be LOAD_PHYSICAL_ADDR,
but not the original kernel loading address 'output'.

The bug will cause kernel boot failure if kernel is loaded at a different
position than the address, 16M, which is decided at compiled time.
Kexec/kdump is such practical case.

To fix it, just assign LOAD_PHYSICAL_ADDR to virt_addr as initial
value.

Tested-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 8391c73 ("x86/KASLR: Randomize virtual address separately")
Link: http://lkml.kernel.org/r/1498567146-11990-3-git-send-email-bhe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/boot/compressed/kaslr.c
arch/x86/boot/compressed/misc.c
arch/x86/boot/compressed/misc.h

index 54c24f0a43d36c02f3e016961c4d5f7cc4ffd029..56a7e9201741033526443f1e14968ba362c492eb 100644 (file)
@@ -564,9 +564,6 @@ void choose_random_location(unsigned long input,
 {
        unsigned long random_addr, min_addr;
 
-       /* By default, keep output position unchanged. */
-       *virt_addr = *output;
-
        if (cmdline_find_option_bool("nokaslr")) {
                warn("KASLR disabled: 'nokaslr' on cmdline.");
                return;
index 6008fa9b74d948ecbeb1193d3bf8973706ae7cec..00241c81552448c9a3877a16eb0183e2d81438ea 100644 (file)
@@ -338,7 +338,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
                                  unsigned long output_len)
 {
        const unsigned long kernel_total_size = VO__end - VO__text;
-       unsigned long virt_addr = (unsigned long)output;
+       unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
 
        /* Retain x86 boot parameters pointer passed from startup_32/64. */
        boot_params = rmode;
@@ -399,7 +399,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
 #ifndef CONFIG_RELOCATABLE
        if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
                error("Destination address does not match LOAD_PHYSICAL_ADDR");
-       if ((unsigned long)output != virt_addr)
+       if (virt_addr != LOAD_PHYSICAL_ADDR)
                error("Destination virtual address changed when not relocatable");
 #endif
 
index 1c8355eadbd199027fd12da0347f5f3f5f2dcf43..766a5211f82768303087818c8da4ef280e688dd0 100644 (file)
@@ -81,8 +81,6 @@ static inline void choose_random_location(unsigned long input,
                                          unsigned long output_size,
                                          unsigned long *virt_addr)
 {
-       /* No change from existing output location. */
-       *virt_addr = *output;
 }
 #endif