aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/mm/init.c
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2016-01-29 05:59:03 -0500
committerCatalin Marinas <catalin.marinas@arm.com>2016-02-24 09:57:27 -0500
commitc031a4213c11a5db475f528c182f7b3858df11db (patch)
tree194b08753fc4dc09977fed71eccfcee48e66f412 /arch/arm64/mm/init.c
parentf80fb3a3d50843a401dac4b566b3b131da8077a2 (diff)
arm64: kaslr: randomize the linear region
When KASLR is enabled (CONFIG_RANDOMIZE_BASE=y), and entropy has been provided by the bootloader, randomize the placement of RAM inside the linear region if sufficient space is available. For instance, on a 4KB granule/3 levels kernel, the linear region is 256 GB in size, and we can choose any 1 GB aligned offset that is far enough from the top of the address space to fit the distance between the start of the lowest memblock and the top of the highest memblock. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Diffstat (limited to 'arch/arm64/mm/init.c')
-rw-r--r--arch/arm64/mm/init.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index c0ea54bd9995..e1f425fe5a81 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -196,6 +196,23 @@ void __init arm64_memblock_init(void)
196 memblock_add(__pa(_text), (u64)(_end - _text)); 196 memblock_add(__pa(_text), (u64)(_end - _text));
197 } 197 }
198 198
199 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
200 extern u16 memstart_offset_seed;
201 u64 range = linear_region_size -
202 (memblock_end_of_DRAM() - memblock_start_of_DRAM());
203
204 /*
205 * If the size of the linear region exceeds, by a sufficient
206 * margin, the size of the region that the available physical
207 * memory spans, randomize the linear region as well.
208 */
209 if (memstart_offset_seed > 0 && range >= ARM64_MEMSTART_ALIGN) {
210 range = range / ARM64_MEMSTART_ALIGN + 1;
211 memstart_addr -= ARM64_MEMSTART_ALIGN *
212 ((range * memstart_offset_seed) >> 16);
213 }
214 }
215
199 /* 216 /*
200 * Register the kernel text, kernel data, initrd, and initial 217 * Register the kernel text, kernel data, initrd, and initial
201 * pagetables with memblock. 218 * pagetables with memblock.
@@ -365,12 +382,13 @@ void __init mem_init(void)
365#ifdef CONFIG_SPARSEMEM_VMEMMAP 382#ifdef CONFIG_SPARSEMEM_VMEMMAP
366 MLG((unsigned long)vmemmap, 383 MLG((unsigned long)vmemmap,
367 (unsigned long)vmemmap + VMEMMAP_SIZE), 384 (unsigned long)vmemmap + VMEMMAP_SIZE),
368 MLM((unsigned long)virt_to_page(PAGE_OFFSET), 385 MLM((unsigned long)phys_to_page(memblock_start_of_DRAM()),
369 (unsigned long)virt_to_page(high_memory)), 386 (unsigned long)virt_to_page(high_memory)),
370#endif 387#endif
371 MLK(FIXADDR_START, FIXADDR_TOP), 388 MLK(FIXADDR_START, FIXADDR_TOP),
372 MLM(PCI_IO_START, PCI_IO_END), 389 MLM(PCI_IO_START, PCI_IO_END),
373 MLM(PAGE_OFFSET, (unsigned long)high_memory)); 390 MLM(__phys_to_virt(memblock_start_of_DRAM()),
391 (unsigned long)high_memory));
374 392
375#undef MLK 393#undef MLK
376#undef MLM 394#undef MLM