xref: /openbmc/linux/arch/arm64/kernel/kaslr.c (revision 9aa2cba7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
4  */
5 
6 #include <linux/cache.h>
7 #include <linux/init.h>
8 #include <linux/printk.h>
9 
10 #include <asm/cpufeature.h>
11 #include <asm/memory.h>
12 
13 u16 __initdata memstart_offset_seed;
14 
15 bool __ro_after_init __kaslr_is_enabled = false;
16 
17 void __init kaslr_init(void)
18 {
19 	if (cpuid_feature_extract_unsigned_field(arm64_sw_feature_override.val &
20 						 arm64_sw_feature_override.mask,
21 						 ARM64_SW_FEATURE_OVERRIDE_NOKASLR)) {
22 		pr_info("KASLR disabled on command line\n");
23 		return;
24 	}
25 
26 	/*
27 	 * The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical
28 	 * placement of the image rather than from the seed, so a displacement
29 	 * of less than MIN_KIMG_ALIGN means that no seed was provided.
30 	 */
31 	if (kaslr_offset() < MIN_KIMG_ALIGN) {
32 		pr_warn("KASLR disabled due to lack of seed\n");
33 		return;
34 	}
35 
36 	pr_info("KASLR enabled\n");
37 	__kaslr_is_enabled = true;
38 }
39