From: Baoquan He <bhe@redhat.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] x86/boot/KASLR: Skip relocation handling in no kaslr case
Date: Mon, 26 Jun 2017 18:43:49 +0800 [thread overview]
Message-ID: <20170626104349.GA3303@x1> (raw)
In-Reply-To: <20170626094737.d2pzetkhe2sorn6m@gmail.com>
Hi Ingo,
Thanks for looking into this patch!
On 06/26/17 at 11:47am, Ingo Molnar wrote:
>
> * Baoquan He <bhe@redhat.com> 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().
>
> So instead of whacking yet another kexec mole, how could we turn this into a more
> debuggable warning (either during build or during the failed bootup) instead of a
> crash and reset (triple fault?) back to the BIOS screen?
This is a good question.
In fact this might not be kexe only problem. It's actually a code bug.
For x86_64, kernel text kaslr is separated into physical and virtual
address randomization. And here the virtual addr randmoization, can only
be done inside [0xffffffff80000000, 0xffffffffc0000000), the 1G area.
When we do the virtual address randomization, we only randomize to get
an offset between 0 and 1G, then add this offset onto the starting
address, 0xffffffff80000000. In the current code, virt_addr represents
the offset, which is a little confusing. In my original patch, it's
named as virt_offset(the link of original patch is pasted below). Kees
helped refactor the code, that corner case could be forgotton.
https://github.com/baoquan-he/linux/commit/034fbed941c60099368a40058cdfd0b4cac76040
If from the point of view of the offset of virtual address, which is among
kernel mapping area [0xffffffff80000000, 0xffffffffc0000000), the 'output'
which is the original loading address of kernel, absolutely should not be
assigned to virt_addr (better renamed as virt_offset or something else).
Here, kexec/kdump is only a pratical use case. I know someone ever
modifed bootloader to make kernel can be loaded arbitrary address, which
is not 16M, decided at compiled time. Then kernel will fail too.
As you suggested, we can add a checking to see if the virt_addr is
bigger than 1G, and print warning if exceed or hang there with error
message.
>
> If kexec/kdump wants to do crazy things they should at least be _debuggable_ in a
> straightforward manner.
So, it may not be fault of kexec/kdump, it's a code bug. I guess we
allow kernel to be loaded at any address, but not the address decided at
compiled time, 16M, right?
Thanks
Baoquan
next prev parent reply other threads:[~2017-06-26 10:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1498314309-18502-1-git-send-email-bhe@redhat.com>
2017-06-26 9:47 ` [PATCH] x86/boot/KASLR: Skip relocation handling in no kaslr case Ingo Molnar
2017-06-26 10:43 ` Baoquan He [this message]
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
2017-06-24 14:16 Baoquan He
2017-06-24 14:23 ` 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=20170626104349.GA3303@x1 \
--to=bhe@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/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