Skip to content

Commit c7d2361

Browse files
thgarnieIngo Molnar
authored andcommitted
x86/mm/KASLR: Fix physical memory calculation on KASLR memory randomization
Initialize KASLR memory randomization after max_pfn is initialized. Also ensure the size is rounded up. It could create problems on machines with more than 1Tb of memory on certain random addresses. Signed-off-by: Thomas Garnier <[email protected]> Cc: Aleksey Makarov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Baoquan He <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Dan Williams <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Young <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Fabian Frederick <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Kees Cook <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Lv Zheng <[email protected]> Cc: Mark Salter <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rafael J . Wysocki <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Toshi Kani <[email protected]> Cc: [email protected] Fixes: 021182e ("Enable KASLR for physical mapping memory regions") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 469f002 commit c7d2361

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

arch/x86/kernel/setup.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,6 @@ void __init setup_arch(char **cmdline_p)
936936

937937
x86_init.oem.arch_setup();
938938

939-
kernel_randomize_memory();
940-
941939
iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
942940
setup_memory_map();
943941
parse_setup_data();
@@ -1055,6 +1053,12 @@ void __init setup_arch(char **cmdline_p)
10551053

10561054
max_possible_pfn = max_pfn;
10571055

1056+
/*
1057+
* Define random base addresses for memory sections after max_pfn is
1058+
* defined and before each memory section base is used.
1059+
*/
1060+
kernel_randomize_memory();
1061+
10581062
#ifdef CONFIG_X86_32
10591063
/* max_low_pfn get updated here */
10601064
find_low_pfn_range();

arch/x86/mm/kaslr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void __init kernel_randomize_memory(void)
9797
* add padding if needed (especially for memory hotplug support).
9898
*/
9999
BUG_ON(kaslr_regions[0].base != &page_offset_base);
100-
memory_tb = ((max_pfn << PAGE_SHIFT) >> TB_SHIFT) +
100+
memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
101101
CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
102102

103103
/* Adapt phyiscal memory region size based on available memory */

0 commit comments

Comments
 (0)