riscv: Do not re-populate shadow memory with kasan_populate_early_shadow
authorAlexandre Ghiti <alexandre.ghiti@canonical.com>
Fri, 29 Oct 2021 04:59:26 +0000 (06:59 +0200)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Fri, 29 Oct 2021 15:53:42 +0000 (08:53 -0700)
commitcf11d01135ea1ff7fddb612033e3cb5cde279ff2
tree086736bb860e8202dc4e21b3af6c16de7f918b41
parent64a19591a2938b170aa736443d5d3bf4c51e1388
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 <alexandre.ghiti@canonical.com>
Fixes: e178d670f251 ("riscv/kasan: add KASAN_VMALLOC support")
Fixes: 8ad8b72721d0 ("riscv: Add KASAN support")
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/mm/kasan_init.c