[PATCH v1 03/11] mm/kasan: handle unaligned end address in zero_pte_populate

From: js1304
Date: Mon May 15 2017 - 21:18:03 EST


From: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>

It doesn't handle unaligned end address so last pte could not
be initialized. Fix it.

Note that this shadow memory can be used by others so map
the actual page in this case.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@xxxxxxx>
---
mm/kasan/kasan_init.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/mm/kasan/kasan_init.c b/mm/kasan/kasan_init.c
index 554e4c0..48559d9 100644
--- a/mm/kasan/kasan_init.c
+++ b/mm/kasan/kasan_init.c
@@ -61,6 +61,14 @@ static void __init zero_pte_populate(pmd_t *pmd, unsigned long addr,
addr += PAGE_SIZE;
pte = pte_offset_kernel(pmd, addr);
}
+
+ if (addr == end)
+ return;
+
+ /* Population for unaligned end address */
+ zero_pte = pfn_pte(PFN_DOWN(
+ __pa(early_alloc(PAGE_SIZE, NUMA_NO_NODE))), PAGE_KERNEL);
+ set_pte_at(&init_mm, addr, pte, zero_pte);
}

static void __init zero_pmd_populate(pud_t *pud, unsigned long addr,
--
2.7.4