Skip to content

Commit cf11d01

Browse files
AlexGhitipalmer-dabbelt
authored andcommitted
riscv: Do not re-populate shadow memory with kasan_populate_early_shadow
When calling this function, all the shadow memory is already populated with kasan_early_shadow_pte which has PAGE_KERNEL protection. kasan_populate_early_shadow write-protects the mapping of the range of addresses passed in argument in zero_pte_populate, which actually write-protects all the shadow memory mapping since kasan_early_shadow_pte is used for all the shadow memory at this point. And then when using memblock API to populate the shadow memory, the first write access to the kernel stack triggers a trap. This becomes visible with the next commit that contains a fix for asan-stack. We already manually populate all the shadow memory in kasan_early_init and we write-protect kasan_early_shadow_pte at the end of kasan_init which makes the calls to kasan_populate_early_shadow superfluous so we can remove them. Signed-off-by: Alexandre Ghiti <[email protected]> Fixes: e178d67 ("riscv/kasan: add KASAN_VMALLOC support") Fixes: 8ad8b72 ("riscv: Add KASAN support") Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 64a1959 commit cf11d01

File tree

1 file changed

+0
-11
lines changed

1 file changed

+0
-11
lines changed

arch/riscv/mm/kasan_init.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,10 @@ void __init kasan_init(void)
172172
phys_addr_t p_start, p_end;
173173
u64 i;
174174

175-
/*
176-
* Populate all kernel virtual address space with kasan_early_shadow_page
177-
* except for the linear mapping and the modules/kernel/BPF mapping.
178-
*/
179-
kasan_populate_early_shadow((void *)KASAN_SHADOW_START,
180-
(void *)kasan_mem_to_shadow((void *)
181-
VMEMMAP_END));
182175
if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
183176
kasan_shallow_populate(
184177
(void *)kasan_mem_to_shadow((void *)VMALLOC_START),
185178
(void *)kasan_mem_to_shadow((void *)VMALLOC_END));
186-
else
187-
kasan_populate_early_shadow(
188-
(void *)kasan_mem_to_shadow((void *)VMALLOC_START),
189-
(void *)kasan_mem_to_shadow((void *)VMALLOC_END));
190179

191180
/* Populate the linear mapping */
192181
for_each_mem_range(i, &p_start, &p_end) {

0 commit comments

Comments
 (0)