[PATCH v3 11/12] arch/um: don't initialize kasan if it's disabled

Baoquan He
2025-08-20T05:37:03Z

And also add code to enable kasan_flag_enabled, this is for later
usage. Since kasan_init() is called before main(), enabling
kasan_flag_enabled is done in arch_mm_preinit() which is after
jump_label_init() invocation.

And also do the kasan_arg_disabled chekcing before kasan_flag_enabled
enabling to make sure kernel parameter kasan=on|off has been parsed.

Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: linux-um@lists.infradead.org
---
arch/um/kernel/mem.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 76bec7de81b5..7b7f838274b5 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -58,6 +58,13 @@ static unsigned long brk_end;

void __init arch_mm_preinit(void)
{
+
+#ifdef CONFIG_KASAN
+ /* Safe to call after jump_label_init(). Enables KASAN. */
+ if (!kasan_arg_disabled)
+ static_branch_enable(&kasan_flag_enabled);
+#endif
+
/* clear the zero-page */
memset(empty_zero_page, 0, PAGE_SIZE);

--
2.41.0