powerpc/fsl_booke/kaslr: clear the original kernel if randomized
authorJason Yan <yanaijie@huawei.com>
Fri, 20 Sep 2019 09:45:42 +0000 (17:45 +0800)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 13 Nov 2019 08:27:44 +0000 (19:27 +1100)
The original kernel still exists in the memory, clear it now.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Diana Craciun <diana.craciun@nxp.com>
Tested-by: Diana Craciun <diana.craciun@nxp.com>
Signed-off-by: Scott Wood <oss@buserror.net>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/mm/mmu_decl.h
arch/powerpc/mm/nohash/fsl_booke.c
arch/powerpc/mm/nohash/kaslr_booke.c

index ae06c5675abbb10cbe82cd2ec1306d607bc216bf..8e99649c24fc4d47341d570a5e29c4e01fb80e95 100644 (file)
@@ -148,8 +148,10 @@ extern void loadcam_multi(int first_idx, int num, int tmp_idx);
 
 #ifdef CONFIG_RANDOMIZE_BASE
 void kaslr_early_init(void *dt_ptr, phys_addr_t size);
+void kaslr_late_init(void);
 #else
 static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {}
+static inline void kaslr_late_init(void) {}
 #endif
 
 struct tlbcam {
index 2dc27cf88add00f24ed952c77e5db73753d43f5c..b4eb06ceb1892ae266dd211170fb9f9535e8586a 100644 (file)
@@ -269,6 +269,7 @@ notrace void __init relocate_init(u64 dt_ptr, phys_addr_t start)
        kernstart_addr = start;
        if (is_second_reloc) {
                virt_phys_offset = PAGE_OFFSET - memstart_addr;
+               kaslr_late_init();
                return;
        }
 
index 7b238fc2c8a936504634e48874388cd3def7c4e8..aa1b60c782e75ed91f45f6ecbd8f020897fe474a 100644 (file)
@@ -381,3 +381,14 @@ notrace void __init kaslr_early_init(void *dt_ptr, phys_addr_t size)
 
        reloc_kernel_entry(dt_ptr, kernstart_virt_addr);
 }
+
+void __init kaslr_late_init(void)
+{
+       /* If randomized, clear the original kernel */
+       if (kernstart_virt_addr != KERNELBASE) {
+               unsigned long kernel_sz;
+
+               kernel_sz = (unsigned long)_end - kernstart_virt_addr;
+               memzero_explicit((void *)KERNELBASE, kernel_sz);
+       }
+}