All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86, boot: skip relocs when load address unchanged
@ 2015-01-16  0:51 Kees Cook
  2015-01-16 11:16 ` Thomas D.
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Kees Cook @ 2015-01-16  0:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, x86, Vivek Goyal,
	Jan Beulich, Junjie Mao, Andi Kleen, Baoquan He, Thomas D.

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 <bhe@redhat.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: stable@vger.kernel.org
---
This is a reimplementation of Baoquan's "kaslr: check if kernel location is
changed", which performs the check without needing to change the function
declaration. This should have exactly the same effect, but I dropped Vivek's
Ack and Thomas's Test, since it's technically a different patch.
---
 arch/x86/boot/compressed/misc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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;
 }
-- 
1.9.1


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-02-26 11:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-16  0:51 [PATCH] x86, boot: skip relocs when load address unchanged Kees Cook
2015-01-16 11:16 ` Thomas D.
2015-01-20 11:42 ` [tip:x86/urgent] x86, boot: Skip " tip-bot for Kees Cook
2015-01-20 13:04 ` [PATCH] x86, boot: skip " Baoquan He
2015-02-26  6:29   ` MegaBrutal
2015-02-26  6:45     ` Baoquan He
     [not found]   ` <CAE8gLh=9S-FMcekB43nM6RaAxEHsPkU0PK_=wNNbMT9YzkZiXw@mail.gmail.com>
2015-02-26 11:50     ` Ingo Molnar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.