Skip to content

Commit f285f4a

Browse files
keesKAGA-KOKO
authored andcommitted
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]>
1 parent 8abb850 commit f285f4a

File tree

1 file changed

+8
-1
lines changed
  • arch/x86/boot/compressed

1 file changed

+8
-1
lines changed

arch/x86/boot/compressed/misc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
373373
unsigned long output_len,
374374
unsigned long run_size)
375375
{
376+
unsigned char *output_orig = output;
377+
376378
real_mode = rmode;
377379

378380
sanitize_boot_params(real_mode);
@@ -421,7 +423,12 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
421423
debug_putstr("\nDecompressing Linux... ");
422424
decompress(input_data, input_len, NULL, NULL, output, NULL, error);
423425
parse_elf(output);
424-
handle_relocations(output, output_len);
426+
/*
427+
* 32-bit always performs relocations. 64-bit relocations are only
428+
* needed if kASLR has chosen a different load address.
429+
*/
430+
if (!IS_ENABLED(CONFIG_X86_64) || output != output_orig)
431+
handle_relocations(output, output_len);
425432
debug_putstr("done.\nBooting the kernel.\n");
426433
return output;
427434
}

0 commit comments

Comments
 (0)