Skip to contentSkip to conversation

kasan: add kasan mode messages when kasan init

PATCH Applied Kuan-Ying Lee 5 participants 5 messages Oct 20, 2021 – Oct 22, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 kasan: add kasan mode messages when kasan init

There are multiple kasan modes. It makes sense that we add some messages to know which kasan mode is when booting up. see [1].

---
v3:
- Rebase to linux-next
- Move kasan_mode_info() into hw_tags.c
v2:
- Rebase to linux-next
- HW-tag based mode need to consider asymm mode
- Thanks Marco's suggestion

 arch/arm64/mm/kasan_init.c |  2 +-
 mm/kasan/hw_tags.c         | 14 +++++++++++++-
 mm/kasan/sw_tags.c         |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)
arch/arm64/mm/kasan_init.c +1 -1
index 5b996ca4d996..6f5a6fe8edd7 100644
@@ -309,7 +309,7 @@ void __init kasan_init(void)
 	kasan_init_depth();
 #if defined(CONFIG_KASAN_GENERIC)
 	/* CONFIG_KASAN_SW_TAGS also requires kasan_init_sw_tags(). */
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (generic)\n");
 #endif
 }
 
mm/kasan/hw_tags.c +13 -1
index dc892119e88f..7355cb534e4f 100644
@@ -106,6 +106,16 @@ static int __init early_kasan_flag_stacktrace(char *arg)
 }
 early_param("kasan.stacktrace", early_kasan_flag_stacktrace);
 
+static inline const char *kasan_mode_info(void)
+{
+	if (kasan_mode == KASAN_MODE_ASYNC)
+		return "async";
+	else if (kasan_mode == KASAN_MODE_ASYMM)
+		return "asymm";
+	else
+		return "sync";
+}
+
 /* kasan_init_hw_tags_cpu() is called for each CPU. */
 void kasan_init_hw_tags_cpu(void)
 {
@@ -177,7 +187,9 @@ void __init kasan_init_hw_tags(void)
 		break;
 	}
 
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (hw-tags, mode=%s, stacktrace=%s)\n",
+		kasan_mode_info(),
+		kasan_stack_collection_enabled() ? "on" : "off");
 }
 
 void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags)
mm/kasan/sw_tags.c +1 -1
index bd3f540feb47..77f13f391b57 100644
@@ -42,7 +42,7 @@ void __init kasan_init_sw_tags(void)
 	for_each_possible_cpu(cpu)
 		per_cpu(prng_state, cpu) = (u32)get_cycles();
 
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (sw-tags)\n");
 }
 
 /*
Signature · 1 line
2.18.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Kuan-Ying Lee

There are multiple kasan modes. It makes sense that we add some messages to know which kasan mode is when booting up. see [1].

Thank you.

Because this is rebased on the changes in the arm64 tree, and also touches arch/arm64, it probably has to go through the arm64 tree.

Quoted 19 lines

---
v3:
- Rebase to linux-next
- Move kasan_mode_info() into hw_tags.c
v2:
- Rebase to linux-next
- HW-tag based mode need to consider asymm mode
- Thanks Marco's suggestion

 arch/arm64/mm/kasan_init.c |  2 +-
 mm/kasan/hw_tags.c         | 14 +++++++++++++-
 mm/kasan/sw_tags.c         |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)
arch/arm64/mm/kasan_init.c +0 -0
index 5b996ca4d996..6f5a6fe8edd7 100644

arch/arm64/mm/kasan_init.c void __init kasan_init(void) · line 314

Quoted 7 lines
arch/arm64/mm/kasan_init.c +1 -1
@@ -309,7 +309,7 @@ void __init kasan_init(void)
        kasan_init_depth();
 #if defined(CONFIG_KASAN_GENERIC)
        /* CONFIG_KASAN_SW_TAGS also requires kasan_init_sw_tags(). */
-       pr_info("KernelAddressSanitizer initialized\n");
+       pr_info("KernelAddressSanitizer initialized (generic)\n");
 #endif
 }

Note: Other architectures may want to update their message once they support any one of the tags modes. But currently that's not yet the case.

You could also consider leaving out the "(generic)" bit if it's the generic mode to avoid adding this to all arch/**/kasan_init.c. Both is fine with me. I leave it to you.

Quoted 47 lines
mm/kasan/hw_tags.c +13 -1
index dc892119e88f..7355cb534e4f 100644
@@ -106,6 +106,16 @@ static int __init early_kasan_flag_stacktrace(char *arg)
 }
 early_param("kasan.stacktrace", early_kasan_flag_stacktrace);
 
+static inline const char *kasan_mode_info(void)
+{
+       if (kasan_mode == KASAN_MODE_ASYNC)
+               return "async";
+       else if (kasan_mode == KASAN_MODE_ASYMM)
+               return "asymm";
+       else
+               return "sync";
+}
+
 /* kasan_init_hw_tags_cpu() is called for each CPU. */
 void kasan_init_hw_tags_cpu(void)
 {
@@ -177,7 +187,9 @@ void __init kasan_init_hw_tags(void)
                break;
        }
 
-       pr_info("KernelAddressSanitizer initialized\n");
+       pr_info("KernelAddressSanitizer initialized (hw-tags, mode=%s, stacktrace=%s)\n",
+               kasan_mode_info(),
+               kasan_stack_collection_enabled() ? "on" : "off");
 }
 
 void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags)
mm/kasan/sw_tags.c +1 -2
index bd3f540feb47..77f13f391b57 100644
@@ -42,7 +42,7 @@ void __init kasan_init_sw_tags(void)
        for_each_possible_cpu(cpu)
                per_cpu(prng_state, cpu) = (u32)get_cycles();
 
-       pr_info("KernelAddressSanitizer initialized\n");
+       pr_info("KernelAddressSanitizer initialized (sw-tags)\n");
 }
 
 /*
--

2.18.0

maintainer
#2 lore raw
Quoted 8 lines · On Wed, 20 Oct 2021 11:58:26 +0200 Marco Elver <[email protected]> wrote:
Quoted 6 lines · Kuan-Ying Lee

There are multiple kasan modes. It makes sense that we add some messages to know which kasan mode is when booting up. see [1].

Quoted 6 lines

Thank you.

Because this is rebased on the changes in the arm64 tree, and also touches arch/arm64, it probably has to go through the arm64 tree.

That would be OK, as long as it doesn't also have dependencies on pending changes elsewhere in the -mm tree.

To solve both potential problems, I've queued it in -mm's post-linux-next section, so it gets sent to Linus after both -mm and arm have merged up.

maintainer
#3 lore raw
Quoted 17 lines · Andrew Morton
Quoted 8 lines · On Wed, 20 Oct 2021 11:58:26 +0200 Marco Elver <[email protected]> wrote:
Quoted 6 lines · Kuan-Ying Lee

There are multiple kasan modes. It makes sense that we add some messages to know which kasan mode is when booting up. see [1].

Quoted 6 lines

Thank you.

Because this is rebased on the changes in the arm64 tree, and also touches arch/arm64, it probably has to go through the arm64 tree.

Quoted 6 lines

That would be OK, as long as it doesn't also have dependencies on pending changes elsewhere in the -mm tree.

To solve both potential problems, I've queued it in -mm's post-linux-next section, so it gets sent to Linus after both -mm and arm have merged up.

Works for me -- I'll ignore this patch then.

Will

Reviewed-by on v3 1/1
#4 lore raw
In reply to Kuan-Ying Lee
Quoted 2 lines · Kuan-Ying Lee

There are multiple kasan modes. It makes sense that we add some messages to know which kasan mode is when booting up. see [1].

s/is/is active/ ?

Looks reasonable to me

Quoted 76 lines

---
v3:
- Rebase to linux-next
- Move kasan_mode_info() into hw_tags.c
v2:
- Rebase to linux-next
- HW-tag based mode need to consider asymm mode
- Thanks Marco's suggestion

 arch/arm64/mm/kasan_init.c |  2 +-
 mm/kasan/hw_tags.c         | 14 +++++++++++++-
 mm/kasan/sw_tags.c         |  2 +-
 3 files changed, 15 insertions(+), 3 deletions(-)
arch/arm64/mm/kasan_init.c +1 -1
index 5b996ca4d996..6f5a6fe8edd7 100644
@@ -309,7 +309,7 @@ void __init kasan_init(void)
 	kasan_init_depth();
 #if defined(CONFIG_KASAN_GENERIC)
 	/* CONFIG_KASAN_SW_TAGS also requires kasan_init_sw_tags(). */
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (generic)\n");
 #endif
 }
 
mm/kasan/hw_tags.c +13 -1
index dc892119e88f..7355cb534e4f 100644
@@ -106,6 +106,16 @@ static int __init early_kasan_flag_stacktrace(char *arg)
 }
 early_param("kasan.stacktrace", early_kasan_flag_stacktrace);
 
+static inline const char *kasan_mode_info(void)
+{
+	if (kasan_mode == KASAN_MODE_ASYNC)
+		return "async";
+	else if (kasan_mode == KASAN_MODE_ASYMM)
+		return "asymm";
+	else
+		return "sync";
+}
+
 /* kasan_init_hw_tags_cpu() is called for each CPU. */
 void kasan_init_hw_tags_cpu(void)
 {
@@ -177,7 +187,9 @@ void __init kasan_init_hw_tags(void)
 		break;
 	}
 
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (hw-tags, mode=%s, stacktrace=%s)\n",
+		kasan_mode_info(),
+		kasan_stack_collection_enabled() ? "on" : "off");
 }
 
 void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags)
mm/kasan/sw_tags.c +1 -1
index bd3f540feb47..77f13f391b57 100644
@@ -42,7 +42,7 @@ void __init kasan_init_sw_tags(void)
 	for_each_possible_cpu(cpu)
 		per_cpu(prng_state, cpu) = (u32)get_cycles();
 
-	pr_info("KernelAddressSanitizer initialized\n");
+	pr_info("KernelAddressSanitizer initialized (sw-tags)\n");
 }
 
 /*
Signature · 3 lines
Thanks,

David / dhildenb