From: Alexander Potapenko Date: Wed, 7 May 2025 16:00:11 +0000 (+0200) Subject: kmsan: enter the runtime around kmsan_internal_memmove_metadata() call X-Git-Tag: v6.16-rc1~92^2~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e17c1f15b0ccfa4802cedbd464d00ece50a10cf1;p=thirdparty%2Flinux.git kmsan: enter the runtime around kmsan_internal_memmove_metadata() call kmsan_internal_memmove_metadata() transitively calls stack_depot_save() (via kmsan_internal_chain_origin() and kmsan_save_stack_with_flags()), which may allocate memory. Guard it with kmsan_enter_runtime() and kmsan_leave_runtime() to avoid recursion. This bug was spotted by CONFIG_WARN_CAPABILITY_ANALYSIS=y Link: https://lkml.kernel.org/r/20250507160012.3311104-4-glider@google.com Signed-off-by: Alexander Potapenko Acked-by: Marco Elver Cc: Bart Van Assche Cc: Kent Overstreet Cc: Dmitriy Vyukov Cc: Ilya Leoshkevich Signed-off-by: Andrew Morton --- diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index 05f2faa540545..97de3d6194f07 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -275,8 +275,10 @@ void kmsan_copy_to_user(void __user *to, const void *from, size_t to_copy, * Don't check anything, just copy the shadow of the copied * bytes. */ + kmsan_enter_runtime(); kmsan_internal_memmove_metadata((void *)to, (void *)from, to_copy - left); + kmsan_leave_runtime(); } user_access_restore(ua_flags); }