Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1459001
| From | Thomas Garnier <thgarnie@google.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v4 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization |
| Date | 2016-08-09 19:20 +0200 |
| Message-ID | <s4iR3-24N-13@gated-at.bofh.it> (permalink) |
| Organization | linux.* mail to news gateway |
Initialize KASLR memory randomization after max_pfn is initialized. Also
ensure the size is rounded up. It could have create problems on machines
with more than 1Tb of memory on certain random addresses.
Fixes: 021182e52fe0 ("Enable KASLR for physical mapping memory regions")
Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20160805
---
arch/x86/kernel/setup.c | 8 ++++++--
arch/x86/mm/kaslr.c | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index bcabb88..dc50644 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();
@@ -1055,6 +1053,12 @@ void __init setup_arch(char **cmdline_p)
max_possible_pfn = max_pfn;
+ /*
+ * Define random base addresses for memory sections after max_pfn is
+ * defined and before each memory section base is used.
+ */
+ kernel_randomize_memory();
+
#ifdef CONFIG_X86_32
/* max_low_pfn get updated here */
find_low_pfn_range();
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
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
[PATCH v4 1/2] x86/KASLR: Fix physical memory calculation on KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 19:20 +0200
[PATCH v4 2/2] x86/KASLR: Increase BRK pages for KASLR memory randomization Thomas Garnier <thgarnie@google.com> - 2016-08-09 19:20 +0200
[tip:x86/mm] x86/mm/KASLR: Increase BRK pages for KASLR memory randomization tip-bot for Thomas Garnier <tipbot@zytor.com> - 2016-08-10 20:20 +0200
[tip:x86/mm] x86/mm/KASLR: Fix physical memory calculation on KASLR memory randomization tip-bot for Thomas Garnier <tipbot@zytor.com> - 2016-08-10 20:20 +0200
csiph-web