Skip to content

Commit c519c3c

Browse files
Alexander Gordeevakpm00
authored andcommitted
mm/kasan: avoid lazy MMU mode hazards
Functions __kasan_populate_vmalloc() and __kasan_depopulate_vmalloc() use apply_to_pte_range(), which enters lazy MMU mode. In that mode updating PTEs may not be observed until the mode is left. That may lead to a situation in which otherwise correct reads and writes to a PTE using ptep_get(), set_pte(), pte_clear() and other access primitives bring wrong results when the vmalloc shadow memory is being (de-)populated. To avoid these hazards leave the lazy MMU mode before and re-enter it after each PTE manipulation. Link: https://lkml.kernel.org/r/0d2efb7ddddbff6b288fbffeeb10166e90771718.1755528662.git.agordeev@linux.ibm.com Fixes: 3c5c3cf ("kasan: support backing vmalloc space with real shadow memory") Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Daniel Axtens <dja@axtens.net> Cc: Marc Rutland <mark.rutland@arm.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 08c7c25 commit c519c3c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mm/kasan/shadow.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,
305305
pte_t pte;
306306
int index;
307307

308+
arch_leave_lazy_mmu_mode();
309+
308310
index = PFN_DOWN(addr - data->start);
309311
page = data->pages[index];
310312
__memset(page_to_virt(page), KASAN_VMALLOC_INVALID, PAGE_SIZE);
@@ -317,6 +319,8 @@ static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr,
317319
}
318320
spin_unlock(&init_mm.page_table_lock);
319321

322+
arch_enter_lazy_mmu_mode();
323+
320324
return 0;
321325
}
322326

@@ -461,6 +465,8 @@ static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr,
461465
pte_t pte;
462466
int none;
463467

468+
arch_leave_lazy_mmu_mode();
469+
464470
spin_lock(&init_mm.page_table_lock);
465471
pte = ptep_get(ptep);
466472
none = pte_none(pte);
@@ -471,6 +477,8 @@ static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr,
471477
if (likely(!none))
472478
__free_page(pfn_to_page(pte_pfn(pte)));
473479

480+
arch_enter_lazy_mmu_mode();
481+
474482
return 0;
475483
}
476484

0 commit comments

Comments
 (0)