[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1493278940-5885-1-git-send-email-bhe@redhat.com>
Date: Thu, 27 Apr 2017 15:42:20 +0800
From: Baoquan He <bhe@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: Baoquan He <bhe@...hat.com>, Dave Young <dyoung@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, x86@...nel.org,
Kees Cook <keescook@...omium.org>,
Yinghai Lu <yinghai@...nel.org>, Borislav Petkov <bp@...e.de>,
Dave Jiang <dave.jiang@...el.com>,
Thomas Garnier <thgarnie@...gle.com>
Subject: [PATCH v2] x86/KASLR: Use old ident map page table if physical randomization failed
Dave found kdump kernel with kaslr enabled will reset to bios immediately
if physical randomization failed to find a new position for kernel. But
kernel with 'nokaslr' option works in this case.
The reason is kaslr will install a new page table for ident mapping,
while it missed to consider building ident mapping for original area
of kernel if kaslr failed on physical randomization.
This only happens in kexec/kdump kernel. Since ident mapping has been
built for kexec/kdump in 1st kernel for the whole memory by calling
init_pgtable(). Here if physical randomizaiton failed, it won't build
ident mapping for the original area of kernel but change to new page
table '_pgtable'. Then kernel will reset to bios immediately caused by
no ident mapping.
While normal kernel won't be impacted because it comes here via
startup_32() and cr3 will be _pgtable already. In startup_32() ident
mapping is built for 0~4G area. In kaslr We just append to the existing
area instead of entirely overwriting it for on-demand ident mapping
building. So ident mapping for the original area of kernel is still
there.
So for fixing it, We just switch to the new ident mapping page table
when physical kaslr succeeds. Otherwise we keep the old page table
unchanged just like nokaslr does.
Signed-off-by: Baoquan He <bhe@...hat.com>
Signed-off-by: Dave Young <dyoung@...hat.com>
Acked-by: Kees Cook <keescook@...omium.org>
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: x86@...nel.org
Cc: Kees Cook <keescook@...omium.org>
Cc: Yinghai Lu <yinghai@...nel.org>
Cc: Borislav Petkov <bp@...e.de>
Cc: Dave Jiang <dave.jiang@...el.com>
Cc: Thomas Garnier <thgarnie@...gle.com>
---
v1->v2:
No code change, just improve patch log to make it clearer.
arch/x86/boot/compressed/kaslr.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index e5eb0c3..7a8b443 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -650,10 +650,16 @@ void choose_random_location(unsigned long input,
add_identity_map(random_addr, output_size);
*output = random_addr;
}
+
+ /*
+ * This actually loads the identity pagetable on x86_64.
+ * And this should only be done only if a new position
+ * is found. Otherwise we should keep the old page table
+ * to make it be like nokaslr case.
+ */
+ finalize_identity_maps();
}
- /* This actually loads the identity pagetable on x86_64. */
- finalize_identity_maps();
/* Pick random virtual address starting from LOAD_PHYSICAL_ADDR. */
if (IS_ENABLED(CONFIG_X86_64))
--
2.5.5
Powered by blists - more mailing lists