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 <glider@google.com>
Acked-by: Marco Elver <elver@google.com>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
pull/1253/head
Alexander Potapenko 2025-05-07 18:00:11 +02:00 committed by Andrew Morton
parent ce6a1c978f
commit e17c1f15b0
1 changed files with 2 additions and 0 deletions

View File

@ -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 * Don't check anything, just copy the shadow of the copied
* bytes. * bytes.
*/ */
kmsan_enter_runtime();
kmsan_internal_memmove_metadata((void *)to, (void *)from, kmsan_internal_memmove_metadata((void *)to, (void *)from,
to_copy - left); to_copy - left);
kmsan_leave_runtime();
} }
user_access_restore(ua_flags); user_access_restore(ua_flags);
} }