path: root/mm/vmalloc.c
diff options
authorKefeng Wang <>2022-01-14 14:04:11 -0800
committerLinus Torvalds <>2022-01-15 16:30:25 +0200
commit60115fa54ad7b913b7cb5844e6b7ffeb842d55f2 (patch)
tree4ede7759696d4377bf92a084f54024b61a5fdc82 /mm/vmalloc.c
parent972fa3a7c17c9d60212e32ecc0205dc585b1e769 (diff)
mm: defer kmemleak object creation of module_alloc()
Yongqiang reports a kmemleak panic when module insmod/rmmod with KASAN enabled(without KASAN_VMALLOC) on x86[1]. When the module area allocates memory, it's kmemleak_object is created successfully, but the KASAN shadow memory of module allocation is not ready, so when kmemleak scan the module's pointer, it will panic due to no shadow memory with KASAN check. module_alloc __vmalloc_node_range kmemleak_vmalloc kmemleak_scan update_checksum kasan_module_alloc kmemleak_ignore Note, there is no problem if KASAN_VMALLOC enabled, the modules area entire shadow memory is preallocated. Thus, the bug only exits on ARCH which supports dynamic allocation of module area per module load, for now, only x86/arm64/s390 are involved. Add a VM_DEFER_KMEMLEAK flags, defer vmalloc'ed object register of kmemleak in module_alloc() to fix this issue. [1] [ fix build] Link: [ simplify ifdefs, per Andrey] Link: Link: Fixes: 793213a82de4 ("s390/kasan: dynamic shadow mem allocation for modules") Fixes: 39d114ddc682 ("arm64: add KASAN support") Fixes: bebf56a1b176 ("kasan: enable instrumentation of global variables") Signed-off-by: Kefeng Wang <> Reported-by: Yongqiang Liu <> Cc: Andrey Konovalov <> Cc: Andrey Ryabinin <> Cc: Dmitry Vyukov <> Cc: Catalin Marinas <> Cc: Will Deacon <> Cc: Heiko Carstens <> Cc: Vasily Gorbik <> Cc: Christian Borntraeger <> Cc: Alexander Gordeev <> Cc: Thomas Gleixner <> Cc: Ingo Molnar <> Cc: Borislav Petkov <> Cc: Dave Hansen <> Cc: Alexander Potapenko <> Cc: Kefeng Wang <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'mm/vmalloc.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index d2a00ad4e1dd..bf3c2fe8f528 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3074,7 +3074,8 @@ again:
size = PAGE_ALIGN(size);
- kmemleak_vmalloc(area, size, gfp_mask);
+ if (!(vm_flags & VM_DEFER_KMEMLEAK))
+ kmemleak_vmalloc(area, size, gfp_mask);
return addr;