xref: /linux/arch/arm64/kernel/kaslr.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f80fb3a3SArd Biesheuvel /*
3f80fb3a3SArd Biesheuvel  * Copyright (C) 2016 Linaro Ltd <ard.biesheuvel@linaro.org>
4f80fb3a3SArd Biesheuvel  */
5f80fb3a3SArd Biesheuvel 
65a9e3e15SJisheng Zhang #include <linux/cache.h>
7f80fb3a3SArd Biesheuvel #include <linux/init.h>
8e46b7103SMark Rutland #include <linux/printk.h>
9f80fb3a3SArd Biesheuvel 
10e46b7103SMark Rutland #include <asm/cpufeature.h>
11f80fb3a3SArd Biesheuvel #include <asm/memory.h>
12f80fb3a3SArd Biesheuvel 
13c031a421SArd Biesheuvel u16 __initdata memstart_offset_seed;
14f80fb3a3SArd Biesheuvel 
156e13b6b9SMark Rutland bool __ro_after_init __kaslr_is_enabled = false;
166e13b6b9SMark Rutland 
kaslr_init(void)176e13b6b9SMark Rutland void __init kaslr_init(void)
18fc5a89f7SArd Biesheuvel {
19*af73b9a2SArd Biesheuvel 	if (kaslr_disabled_cmdline()) {
20fc5a89f7SArd Biesheuvel 		pr_info("KASLR disabled on command line\n");
216e13b6b9SMark Rutland 		return;
22fc5a89f7SArd Biesheuvel 	}
23fc5a89f7SArd Biesheuvel 
246e13b6b9SMark Rutland 	/*
256e13b6b9SMark Rutland 	 * The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical
266e13b6b9SMark Rutland 	 * placement of the image rather than from the seed, so a displacement
276e13b6b9SMark Rutland 	 * of less than MIN_KIMG_ALIGN means that no seed was provided.
286e13b6b9SMark Rutland 	 */
296e13b6b9SMark Rutland 	if (kaslr_offset() < MIN_KIMG_ALIGN) {
30fc5a89f7SArd Biesheuvel 		pr_warn("KASLR disabled due to lack of seed\n");
316e13b6b9SMark Rutland 		return;
32fc5a89f7SArd Biesheuvel 	}
33fc5a89f7SArd Biesheuvel 
34fc5a89f7SArd Biesheuvel 	pr_info("KASLR enabled\n");
356e13b6b9SMark Rutland 	__kaslr_is_enabled = true;
36f80fb3a3SArd Biesheuvel }
3750f17617SArd Biesheuvel 
parse_nokaslr(char * unused)3850f17617SArd Biesheuvel static int __init parse_nokaslr(char *unused)
3950f17617SArd Biesheuvel {
4050f17617SArd Biesheuvel 	/* nokaslr param handling is done by early cpufeature code */
4150f17617SArd Biesheuvel 	return 0;
4250f17617SArd Biesheuvel }
4350f17617SArd Biesheuvel early_param("nokaslr", parse_nokaslr);
44