@@ -4,7 +4,7 @@
#include <linux/static_key.h>
-#ifdef CONFIG_KASAN_HW_TAGS
+#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled);
@@ -13,23 +13,18 @@ static __always_inline bool kasan_enabled(void)
return static_branch_likely(&kasan_flag_enabled);
}
-static inline bool kasan_hw_tags_enabled(void)
-{
- return kasan_enabled();
-}
-
-#else /* CONFIG_KASAN_HW_TAGS */
+#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */
static inline bool kasan_enabled(void)
{
return IS_ENABLED(CONFIG_KASAN);
}
+#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */
+
static inline bool kasan_hw_tags_enabled(void)
{
- return false;
+ return IS_ENABLED(CONFIG_KASAN_HW_TAGS) && kasan_enabled();
}
-#endif /* CONFIG_KASAN_HW_TAGS */
-
#endif /* LINUX_KASAN_ENABLED_H */
@@ -43,13 +43,6 @@ static enum kasan_arg kasan_arg __ro_after_init;
static enum kasan_arg_mode kasan_arg_mode __ro_after_init;
static enum kasan_arg_vmalloc kasan_arg_vmalloc __initdata;
-/*
- * Whether KASAN is enabled at all.
- * The value remains false until KASAN is initialized by kasan_init_hw_tags().
- */
-DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled);
-EXPORT_SYMBOL(kasan_flag_enabled);
-
/*
* Whether the selected mode is synchronous, asynchronous, or asymmetric.
* Defaults to KASAN_MODE_SYNC.
@@ -257,9 +250,6 @@ void __init kasan_init_hw_tags(void)
kasan_init_tags();
- /* KASAN is now initialized, enable it. */
- static_branch_enable(&kasan_flag_enabled);
-
pr_info("KernelAddressSanitizer initialized (hw-tags, mode=%s, vmalloc=%s, stacktrace=%s)\n",
kasan_mode_info(),
kasan_vmalloc_enabled() ? "on" : "off",
@@ -32,6 +32,13 @@ enum kasan_arg_stacktrace {
static enum kasan_arg_stacktrace kasan_arg_stacktrace __initdata;
+/*
+ * Whether KASAN is enabled at all.
+ * The value remains false until KASAN is initialized by kasan_init_tags().
+ */
+DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled);
+EXPORT_SYMBOL(kasan_flag_enabled);
+
/* Whether to collect alloc/free stack traces. */
DEFINE_STATIC_KEY_TRUE(kasan_flag_stacktrace);
@@ -92,6 +99,9 @@ void __init kasan_init_tags(void)
if (WARN_ON(!stack_ring.entries))
static_branch_disable(&kasan_flag_stacktrace);
}
+
+ /* KASAN is now initialized, enable it. */
+ static_branch_enable(&kasan_flag_enabled);
}
static void save_stack_info(struct kmem_cache *cache, void *object,