kaslr.c (9d4d8572a539ef807e21c196f145aa365fd52f0e) kaslr.c (f6f0c4362f070cab4a0cec432e82428d702ce0a6)
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/crc32.h>
8#include <linux/init.h>

--- 5 unchanged lines hidden (view full) ---

14#include <linux/random.h>
15
16#include <asm/cacheflush.h>
17#include <asm/fixmap.h>
18#include <asm/kernel-pgtable.h>
19#include <asm/memory.h>
20#include <asm/mmu.h>
21#include <asm/sections.h>
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/crc32.h>
8#include <linux/init.h>

--- 5 unchanged lines hidden (view full) ---

14#include <linux/random.h>
15
16#include <asm/cacheflush.h>
17#include <asm/fixmap.h>
18#include <asm/kernel-pgtable.h>
19#include <asm/memory.h>
20#include <asm/mmu.h>
21#include <asm/sections.h>
22#include <asm/setup.h>
22
23enum kaslr_status {
24 KASLR_ENABLED,
25 KASLR_DISABLED_CMDLINE,
26 KASLR_DISABLED_NO_SEED,
27 KASLR_DISABLED_FDT_REMAP,
28};
29

--- 57 unchanged lines hidden (view full) ---

87/*
88 * This routine will be executed with the kernel mapped at its default virtual
89 * address, and if it returns successfully, the kernel will be remapped, and
90 * start_kernel() will be executed from a randomized virtual offset. The
91 * relocation will result in all absolute references (e.g., static variables
92 * containing function pointers) to be reinitialized, and zero-initialized
93 * .bss variables will be reset to 0.
94 */
23
24enum kaslr_status {
25 KASLR_ENABLED,
26 KASLR_DISABLED_CMDLINE,
27 KASLR_DISABLED_NO_SEED,
28 KASLR_DISABLED_FDT_REMAP,
29};
30

--- 57 unchanged lines hidden (view full) ---

88/*
89 * This routine will be executed with the kernel mapped at its default virtual
90 * address, and if it returns successfully, the kernel will be remapped, and
91 * start_kernel() will be executed from a randomized virtual offset. The
92 * relocation will result in all absolute references (e.g., static variables
93 * containing function pointers) to be reinitialized, and zero-initialized
94 * .bss variables will be reset to 0.
95 */
95u64 __init kaslr_early_init(u64 dt_phys)
96u64 __init kaslr_early_init(void)
96{
97 void *fdt;
98 u64 seed, offset, mask, module_range;
99 unsigned long raw;
97{
98 void *fdt;
99 u64 seed, offset, mask, module_range;
100 unsigned long raw;
100 int size;
101
102 /*
103 * Set a reasonable default for module_alloc_base in case
104 * we end up running with module randomization disabled.
105 */
106 module_alloc_base = (u64)_etext - MODULES_VSIZE;
107 __flush_dcache_area(&module_alloc_base, sizeof(module_alloc_base));
108
109 /*
110 * Try to map the FDT early. If this fails, we simply bail,
111 * and proceed with KASLR disabled. We will make another
112 * attempt at mapping the FDT in setup_machine()
113 */
101
102 /*
103 * Set a reasonable default for module_alloc_base in case
104 * we end up running with module randomization disabled.
105 */
106 module_alloc_base = (u64)_etext - MODULES_VSIZE;
107 __flush_dcache_area(&module_alloc_base, sizeof(module_alloc_base));
108
109 /*
110 * Try to map the FDT early. If this fails, we simply bail,
111 * and proceed with KASLR disabled. We will make another
112 * attempt at mapping the FDT in setup_machine()
113 */
114 early_fixmap_init();
115 fdt = fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL);
114 fdt = get_early_fdt_ptr();
116 if (!fdt) {
117 kaslr_status = KASLR_DISABLED_FDT_REMAP;
118 return 0;
119 }
120
121 /*
122 * Retrieve (and wipe) the seed from the FDT
123 */

--- 106 unchanged lines hidden ---
115 if (!fdt) {
116 kaslr_status = KASLR_DISABLED_FDT_REMAP;
117 return 0;
118 }
119
120 /*
121 * Retrieve (and wipe) the seed from the FDT
122 */

--- 106 unchanged lines hidden ---