Thread (32 messages) 32 messages, 5 authors, 2025-08-04

Re: [PATCH v3 08/12] kasan/um: select ARCH_DEFER_KASAN and call kasan_init_generic

From: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Date: 2025-07-23 17:11:26
Also in: linux-mm, linux-riscv, linux-s390, linux-um, lkml, loongarch


On 7/22/25 4:17 PM, Sabyrzhan Tasbolatov wrote:
On Tue, Jul 22, 2025 at 4:00 AM Andrey Ryabinin [off-list ref] wrote:
quoted


On 7/17/25 4:27 PM, Sabyrzhan Tasbolatov wrote:
quoted
UserMode Linux needs deferred KASAN initialization as it has a custom
kasan_arch_is_ready() implementation that tracks shadow memory readiness
via the kasan_um_is_ready flag.

Select ARCH_DEFER_KASAN to enable the unified static key mechanism
for runtime KASAN control. Call kasan_init_generic() which handles
Generic KASAN initialization and enables the static key.

Delete the key kasan_um_is_ready in favor of the unified kasan_enabled()
interface.

Note that kasan_init_generic has __init macro, which is called by
kasan_init() which is not marked with __init in arch/um code.

Closes: https://bugzilla.kernel.org/show_bug.cgi?id=217049
Signed-off-by: Sabyrzhan Tasbolatov <redacted>
---
Changes in v3:
- Added CONFIG_ARCH_DEFER_KASAN selection for proper runtime control
---
 arch/um/Kconfig             | 1 +
 arch/um/include/asm/kasan.h | 5 -----
 arch/um/kernel/mem.c        | 4 ++--
 3 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index f08e8a7fac9..fd6d78bba52 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -8,6 +8,7 @@ config UML
      select ARCH_WANTS_DYNAMIC_TASK_STRUCT
      select ARCH_HAS_CPU_FINALIZE_INIT
      select ARCH_HAS_FORTIFY_SOURCE
+     select ARCH_DEFER_KASAN
      select ARCH_HAS_GCOV_PROFILE_ALL
      select ARCH_HAS_KCOV
      select ARCH_HAS_STRNCPY_FROM_USER
diff --git a/arch/um/include/asm/kasan.h b/arch/um/include/asm/kasan.h
index f97bb1f7b85..81bcdc0f962 100644
--- a/arch/um/include/asm/kasan.h
+++ b/arch/um/include/asm/kasan.h
@@ -24,11 +24,6 @@

 #ifdef CONFIG_KASAN
 void kasan_init(void);
-extern int kasan_um_is_ready;
-
-#ifdef CONFIG_STATIC_LINK
-#define kasan_arch_is_ready() (kasan_um_is_ready)
-#endif
 #else
 static inline void kasan_init(void) { }
 #endif /* CONFIG_KASAN */
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 76bec7de81b..058cb70e330 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -21,9 +21,9 @@
 #include <os.h>
 #include <um_malloc.h>
 #include <linux/sched/task.h>
+#include <linux/kasan.h>

 #ifdef CONFIG_KASAN
-int kasan_um_is_ready;
 void kasan_init(void)
 {
      /*
@@ -32,7 +32,7 @@ void kasan_init(void)
       */
      kasan_map_memory((void *)KASAN_SHADOW_START, KASAN_SHADOW_SIZE);
      init_task.kasan_depth = 0;
-     kasan_um_is_ready = true;
+     kasan_init_generic();
I think this runs before jump_label_init(), and static keys shouldn't be switched before that.>  }
I got the warning in my local compilation and from kernel CI [1].

arch/um places kasan_init() in own `.kasan_init` section, while
kasan_init_generic() is called from __init.
No, kasan_init() is in text section as the warning says. It's kasan_init_ptr in .kasan_init.
Adding __init to kasan_init() should fix the warning.

Could you suggest a way how I can verify the functions call order?
By code inspection? or run uder gdb.

kasan_init() is initialization routine called before main().
jump_label_init() called from start_kernel()<-start_kernel_proc()<-... main()
I need to familiarize myself with how to run arch/um locally 
It's as simple as:
ARCH=um  make 
./linux rootfstype=hostfs ro init=/bin/bash

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help