Skip to content

Commit af3d0a6

Browse files
chleroympe
authored andcommitted
powerpc/kasan: Fix shadow memory protection with CONFIG_KASAN_VMALLOC
With CONFIG_KASAN_VMALLOC, new page tables are created at the time shadow memory for vmalloc area is unmapped. If some parts of the page table still have entries to the zero page shadow memory, the entries are wrongly marked RW. With CONFIG_KASAN_VMALLOC, almost the entire kernel address space is managed by KASAN. To make it simple, just create KASAN page tables for the entire kernel space at kasan_init(). That doesn't use much more space, and that's anyway already done for hash platforms. Fixes: 3d4247f ("powerpc/32: Add support of KASAN_VMALLOC") Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/ef5248fc1f496c6b0dfdb59380f24968f25f75c5.1583513368.git.christophe.leroy@c-s.fr
1 parent 59bee45 commit af3d0a6

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

arch/powerpc/mm/kasan/kasan_init_32.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ static void __init kasan_unmap_early_shadow_vmalloc(void)
120120
unsigned long k_cur;
121121
phys_addr_t pa = __pa(kasan_early_shadow_page);
122122

123-
if (!early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
124-
int ret = kasan_init_shadow_page_tables(k_start, k_end);
125-
126-
if (ret)
127-
panic("kasan: kasan_init_shadow_page_tables() failed");
128-
}
129123
for (k_cur = k_start & PAGE_MASK; k_cur < k_end; k_cur += PAGE_SIZE) {
130124
pmd_t *pmd = pmd_offset(pud_offset(pgd_offset_k(k_cur), k_cur), k_cur);
131125
pte_t *ptep = pte_offset_kernel(pmd, k_cur);
@@ -143,7 +137,8 @@ void __init kasan_mmu_init(void)
143137
int ret;
144138
struct memblock_region *reg;
145139

146-
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE)) {
140+
if (early_mmu_has_feature(MMU_FTR_HPTE_TABLE) ||
141+
IS_ENABLED(CONFIG_KASAN_VMALLOC)) {
147142
ret = kasan_init_shadow_page_tables(KASAN_SHADOW_START, KASAN_SHADOW_END);
148143

149144
if (ret)

0 commit comments

Comments
 (0)