From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/boot/KASLR: Skip relocation handling in no kaslr case
Date: Sat, 24 Jun 2017 22:23:44 +0800 [thread overview]
Message-ID: <20170624142344.GB2412@x1> (raw)
In-Reply-To: <1498313793-18278-1-git-send-email-bhe@redhat.com>
Sorry, forgot adding Cc: before maintainers contact, NACK this patch and
will repost.
On 06/24/17 at 10:16pm, Baoquan He wrote:
> Kdump kernel will reset to firmware after crash is trigered when
> crashkernel=xxM,high is added to kernel command line. Kexec has the
> same phenomenon. This only happened on system with kaslr code
> compiled in and kernel option 'nokaslr'is added. Both of them works
> well when kaslr is enabled.
>
> When crashkernel high is set or kexec case, kexec/kdump kernel will be
> put above 4G. Since we assign the original loading address of kernel to
> virt_addr as initial value, the virt_addr will be larger than 1G if kaslr
> is disabled, it exceeds the kernel mapping size which is only 1G. Then
> it will cause relocation handling error in handle_relocations().
>
> In fact this is a known issue and fixed in commit:
>
> ... f285f4a ("x86, boot: Skip relocs when load address unchanged")
>
> But above fix was lost carelessly in later commit:
>
> ... 8391c73 ("x86/KASLR: Randomize virtual address separately")
>
> To fix it, just assign LOAD_PHYSICAL_ADDR to virt_addr as initial value.
> If no kaslr is taken, it will skip the relocation handling and jump out.
>
> Fixes: 8391c73 ("x86/KASLR: Randomize virtual address separately")
> Tested-by: Dave Young <dyoung@redhat.com>
> Signed-off-by: Baoquan He <bhe@redhat.com>
> "H. Peter Anvin" <hpa@zytor.com>
> Thomas Gleixner <tglx@linutronix.de>
> Ingo Molnar <mingo@redhat.com>
> x86@kernel.org
> Kees Cook <keescook@chromium.org
> Baoquan He <bhe@redhat.com>
> Dave Jiang <dave.jiang@intel.com>
> Yinghai Lu <yinghai@kernel.org>
> Arnd Bergmann <arnd@arndb.de>
> Thomas Garnier <thgarnie@google.com>
> ---
> arch/x86/boot/compressed/kaslr.c | 3 ---
> arch/x86/boot/compressed/misc.c | 4 ++--
> arch/x86/boot/compressed/misc.h | 2 --
> 3 files changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> index fe318b4..91f27ab 100644
> --- a/arch/x86/boot/compressed/kaslr.c
> +++ b/arch/x86/boot/compressed/kaslr.c
> @@ -625,9 +625,6 @@ void choose_random_location(unsigned long input,
> {
> unsigned long random_addr, min_addr;
>
> - /* By default, keep output position unchanged. */
> - *virt_addr = *output;
> -
> if (cmdline_find_option_bool("nokaslr")) {
> warn("KASLR disabled: 'nokaslr' on cmdline.");
> return;
> diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
> index b3c5a5f0..c945acd 100644
> --- a/arch/x86/boot/compressed/misc.c
> +++ b/arch/x86/boot/compressed/misc.c
> @@ -338,7 +338,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
> unsigned long output_len)
> {
> const unsigned long kernel_total_size = VO__end - VO__text;
> - unsigned long virt_addr = (unsigned long)output;
> + unsigned long virt_addr = LOAD_PHYSICAL_ADDR;
>
> /* Retain x86 boot parameters pointer passed from startup_32/64. */
> boot_params = rmode;
> @@ -397,7 +397,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
> #ifndef CONFIG_RELOCATABLE
> if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
> error("Destination address does not match LOAD_PHYSICAL_ADDR");
> - if ((unsigned long)output != virt_addr)
> + if (virt_addr != LOAD_PHYSICAL_ADDR)
> error("Destination virtual address changed when not relocatable");
> #endif
>
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index 1c8355e..766a521 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -81,8 +81,6 @@ static inline void choose_random_location(unsigned long input,
> unsigned long output_size,
> unsigned long *virt_addr)
> {
> - /* No change from existing output location. */
> - *virt_addr = *output;
> }
> #endif
>
> --
> 2.5.5
>
next prev parent reply other threads:[~2017-06-24 14:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-24 14:16 [PATCH] x86/boot/KASLR: Skip relocation handling in no kaslr case Baoquan He
2017-06-24 14:23 ` Baoquan He [this message]
[not found] <1498314309-18502-1-git-send-email-bhe@redhat.com>
2017-06-26 9:47 ` Ingo Molnar
2017-06-26 10:43 ` Baoquan He
2017-06-27 8:34 ` Ingo Molnar
2017-06-27 8:55 ` Baoquan He
2017-06-27 22:42 ` Kees Cook
2017-06-27 23:24 ` Baoquan He
2017-06-27 23:33 ` Baoquan He
2017-07-05 19:06 ` Kees Cook
2017-07-06 13:28 ` Baoquan He
2017-07-06 13:54 ` Baoquan He
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=20170624142344.GB2412@x1 \
--to=bhe@redhat.com \
--cc=linux-kernel@vger.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 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.