mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] x86, kaslr: Access the correct kaslr_enabled variable
@ 2015-03-15  7:49 Yinghai Lu
  2015-03-15 12:18 ` Minfei Huang
  2015-03-16  3:28 ` Baoquan He
  0 siblings, 2 replies; 9+ messages in thread
From: Yinghai Lu @ 2015-03-15  7:49 UTC (permalink / raw)
  To: H. Peter Anvin, Ingo Molnar, Kees Cook, Borislav Petkov, Baoquan He
  Cc: Thomas Gleixner, Jiri Kosina, Andrew Morton, Linus Torvalds,
	linux-kernel, Yinghai Lu, Matt Fleming

While trying to optimize setup_data handling code, found commit f47233c2d34f
("x86/mm/ASLR: Propagate base load address calculation"), uses a physical
address as the value.

It leads to wrong kaslr status. That kaslr status is passed for controlling
module load offset. So when kernel has kasl support compiled in, and user
use nokaslr to disable kaslr, wrong value cause unwanted offset for module
loading.

We should keep kaslr status consistent between aslr randrom kernel base,
and late module random offset. That is old behavior before that commit.

The setup_data linked list and thus the element which contains
kaslr_enabled is chained together using physical addresses. At the time
when we access it in the kernel, we're already running with paging enabled
and therefore must access it through its virtual address.

This patch changes the code to use early_memmap() and access the value,
as it is still in kernel early stage, we don't have kernel mapping setup
yet.

Fixes: f47233c2d34f ("x86/mm/ASLR: Propagate base load address calculation")
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
-v3: add checking return from early_memmap according to Boris.
-v4: add description about setup_data accessing from Boris to change log.

---
 arch/x86/kernel/setup.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/kernel/setup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup.c
+++ linux-2.6/arch/x86/kernel/setup.c
@@ -429,7 +429,18 @@ static void __init reserve_initrd(void)
 
 static void __init parse_kaslr_setup(u64 pa_data, u32 data_len)
 {
-	kaslr_enabled = (bool)(pa_data + sizeof(struct setup_data));
+	/* kaslr_setup_data is defined in aslr.c */
+	unsigned char *data;
+	unsigned long offset = sizeof(struct setup_data);
+
+	data = early_memremap(pa_data, offset + 1);
+	if (!data) {
+		kaslr_enabled = true;
+		return;
+	}
+
+	kaslr_enabled = *(data + offset);
+	early_memunmap(data, offset + 1);
 }
 
 static void __init parse_setup_data(void)

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

end of thread, other threads:[~2015-03-16  5:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-15  7:49 [PATCH v4] x86, kaslr: Access the correct kaslr_enabled variable Yinghai Lu
2015-03-15 12:18 ` Minfei Huang
2015-03-15 17:02   ` Yinghai Lu
2015-03-16  3:08     ` Minfei Huang
2015-03-16  3:28 ` Baoquan He
2015-03-16  4:36   ` Yinghai Lu
2015-03-16  5:11     ` Baoquan He
2015-03-16  5:04   ` Yinghai Lu
2015-03-16  5:19     ` Baoquan He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®