linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization
@ 2016-08-08 18:40 Thomas Garnier
  2016-08-08 18:40 ` [PATCH v1 2/2] x86/KASLR: Increase BRK pages for " Thomas Garnier
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Thomas Garnier @ 2016-08-08 18:40 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Borislav Petkov,
	Joerg Roedel, Dave Young, Rafael J . Wysocki, Lv Zheng,
	Thomas Garnier, Baoquan He, Dave Hansen, Mark Salter,
	Aleksey Makarov, Kees Cook, Andrew Morton, Christian Borntraeger,
	Fabian Frederick, Toshi Kani, Dan Williams
  Cc: x86, linux-kernel, kernel-hardening

Initialize KASLR memory randomization after max_pfn is initialized. Also
ensure the size is rounded up. Could have create problems on machines
with more than 1Tb of memory on certain random addresses.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160805
---
 arch/x86/kernel/setup.c | 4 ++--
 arch/x86/mm/kaslr.c     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bcabb88..8dda0ce 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.oem.arch_setup();
 
-	kernel_randomize_memory();
-
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
 	setup_memory_map();
 	parse_setup_data();
@@ -1071,6 +1069,8 @@ void __init setup_arch(char **cmdline_p)
 	high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1;
 #endif
 
+	kernel_randomize_memory();
+
 	/*
 	 * Find and reserve possible boot-time SMP configuration:
 	 */
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 26dccd6..ec8654f 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
 	 * add padding if needed (especially for memory hotplug support).
 	 */
 	BUG_ON(kaslr_regions[0].base != &page_offset_base);
-	memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) +
+	memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
 		CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
 
 	/* Adapt phyiscal memory region size based on available memory */
-- 
2.8.0.rc3.226.g39d4020

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

end of thread, other threads:[~2016-08-09 16:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-08 18:40 [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier
2016-08-08 18:40 ` [PATCH v1 2/2] x86/KASLR: Increase BRK pages for " Thomas Garnier
2016-08-09  4:01   ` Borislav Petkov
2016-08-09  4:14     ` H. Peter Anvin
2016-08-09  5:16   ` Mika Penttilä
2016-08-09 14:47     ` Thomas Garnier
2016-08-09 15:07 ` [lkp] [x86/KASLR] 20067c4c13: kernel BUG at arch/x86/mm/physaddr.c:26! kernel test robot
2016-08-09 16:00 ` [PATCH v1 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier
2016-08-09 16:03   ` Joerg Roedel
2016-08-09 16:30     ` Thomas Garnier

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).