aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKees Cook <[email protected]>2015-01-15 16:51:46 -0800
committerThomas Gleixner <[email protected]>2015-01-20 12:37:23 +0100
commitf285f4a21c3253887caceed493089ece17579d59 (patch)
tree17d7cc4556d5a1b144b49f79064cdfa222789441
parent8abb850a03a3a8b11a0e92949e5b99d9cc178e35 (diff)
x86, boot: Skip relocs when load address unchanged
On 64-bit, relocation is not required unless the load address gets changed. Without this, relocations do unexpected things when the kernel is above 4G. Reported-by: Baoquan He <[email protected]> Signed-off-by: Kees Cook <[email protected]> Tested-by: Thomas D. <[email protected]> Cc: Vivek Goyal <[email protected]> Cc: Jan Beulich <[email protected]> Cc: Junjie Mao <[email protected]> Cc: Andi Kleen <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
-rw-r--r--arch/x86/boot/compressed/misc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index dcc1c536cc21..a950864a64da 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -373,6 +373,8 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
unsigned long output_len,
unsigned long run_size)
{
+ unsigned char *output_orig = output;
+
real_mode = rmode;
sanitize_boot_params(real_mode);
@@ -421,7 +423,12 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
debug_putstr("\nDecompressing Linux... ");
decompress(input_data, input_len, NULL, NULL, output, NULL, error);
parse_elf(output);
- handle_relocations(output, output_len);
+ /*
+ * 32-bit always performs relocations. 64-bit relocations are only
+ * needed if kASLR has chosen a different load address.
+ */
+ if (!IS_ENABLED(CONFIG_X86_64) || output != output_orig)
+ handle_relocations(output, output_len);
debug_putstr("done.\nBooting the kernel.\n");
return output;
}