From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, Vivek Goyal <vgoyal@redhat.com>,
Jan Beulich <JBeulich@suse.com>,
Junjie Mao <eternal.n08@gmail.com>,
Andi Kleen <ak@linux.intel.com>, Baoquan He <bhe@redhat.com>,
"Thomas D." <whissi@whissi.de>
Subject: [PATCH] x86, boot: skip relocs when load address unchanged
Date: Thu, 15 Jan 2015 16:51:46 -0800 [thread overview]
Message-ID: <20150116005146.GA4212@www.outflux.net> (raw)
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
next reply other threads:[~2015-01-16 0:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-16 0:51 Kees Cook [this message]
2015-01-16 11:16 ` [PATCH] x86, boot: skip relocs when load address unchanged 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150116005146.GA4212@www.outflux.net \
--to=keescook@chromium.org \
--cc=JBeulich@suse.com \
--cc=ak@linux.intel.com \
--cc=bhe@redhat.com \
--cc=eternal.n08@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=vgoyal@redhat.com \
--cc=whissi@whissi.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).