aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2016-05-25 18:45:34 -0400
committerIngo Molnar <mingo@kernel.org>2016-06-26 06:32:05 -0400
commite066cc47776a89bbdaf4184c0e75f7d389f9ab48 (patch)
treecd6d697abace1c3101b2e68c2783d22893a84d4f /arch/x86/boot
parented9f007ee68478f6a50ec9971ade25a0129a5c0e (diff)
x86/KASLR: Allow randomization below the load address
Currently the kernel image physical address randomization's lower boundary is the original kernel load address. For bootloaders that load kernels into very high memory (e.g. kexec), this means randomization takes place in a very small window at the top of memory, ignoring the large region of physical memory below the load address. Since mem_avoid[] is already correctly tracking the regions that must be avoided, this patch changes the minimum address to whatever is less: 512M (to conservatively avoid unknown things in lower memory) or the load address. Now, for example, if the kernel is loaded at 8G, [512M, 8G) will be added to the list of possible physical memory positions. Signed-off-by: Yinghai Lu <yinghai@kernel.org> [ Rewrote the changelog, refactored the code to use min(). ] Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Baoquan He <bhe@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: H.J. Lu <hjl.tools@gmail.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1464216334-17200-6-git-send-email-keescook@chromium.org [ Edited the changelog some more, plus the code comment as well. ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/compressed/kaslr.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 36e28112523a..749c9e00c674 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -492,7 +492,7 @@ void choose_random_location(unsigned long input,
492 unsigned long output_size, 492 unsigned long output_size,
493 unsigned long *virt_addr) 493 unsigned long *virt_addr)
494{ 494{
495 unsigned long random_addr; 495 unsigned long random_addr, min_addr;
496 496
497 /* By default, keep output position unchanged. */ 497 /* By default, keep output position unchanged. */
498 *virt_addr = *output; 498 *virt_addr = *output;
@@ -510,8 +510,15 @@ void choose_random_location(unsigned long input,
510 /* Record the various known unsafe memory ranges. */ 510 /* Record the various known unsafe memory ranges. */
511 mem_avoid_init(input, input_size, *output); 511 mem_avoid_init(input, input_size, *output);
512 512
513 /*
514 * Low end of the randomization range should be the
515 * smaller of 512M or the initial kernel image
516 * location:
517 */
518 min_addr = min(*output, 512UL << 20);
519
513 /* Walk e820 and find a random address. */ 520 /* Walk e820 and find a random address. */
514 random_addr = find_random_phys_addr(*output, output_size); 521 random_addr = find_random_phys_addr(min_addr, output_size);
515 if (!random_addr) { 522 if (!random_addr) {
516 warn("KASLR disabled: could not find suitable E820 region!"); 523 warn("KASLR disabled: could not find suitable E820 region!");
517 } else { 524 } else {