Skip to contentSkip to conversation

kasan: fix stack traces dependency for HW_TAGS

PATCH Applied Andrey Konovalov 2 participants 2 messages Feb 8, 2021

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

PATCH 1/1 kasan: fix stack traces dependency for HW_TAGS

Currently, whether the alloc/free stack traces collection is enabled by default for hardware tag-based KASAN depends on CONFIG_DEBUG_KERNEL. The intention for this dependency was to only enable collection on slow debug kernels due to a significant perf and memory impact.

As it turns out, CONFIG_DEBUG_KERNEL is not considered a debug option and is enabled on many productions kernels including Android and Ubuntu. As the result, this dependency is pointless and only complicates the code and documentation.

Having stack traces collection disabled by default would make the hardware mode work differently to to the software ones, which is confusing.

This change removes the dependency and enables stack traces collection by default.

Looking into the future, this default might makes sense for production kernels, assuming we implement a fast stack trace collection approach.

---
 Documentation/dev-tools/kasan.rst | 3 +--
 mm/kasan/hw_tags.c                | 8 ++------
 2 files changed, 3 insertions(+), 8 deletions(-)
Documentation/dev-tools/kasan.rst +1 -2
index 1651d961f06a..a248ac3941be 100644
@@ -163,8 +163,7 @@ particular KASAN features.
 - ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
 
 - ``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack
-  traces collection (default: ``on`` for ``CONFIG_DEBUG_KERNEL=y``, otherwise
-  ``off``).
+  traces collection (default: ``on``).
 
 - ``kasan.fault=report`` or ``=panic`` controls whether to only print a KASAN
   report or also panic the kernel (default: ``report``).
mm/kasan/hw_tags.c +2 -6
index e529428e7a11..d558799b25b3 100644
@@ -134,12 +134,8 @@ void __init kasan_init_hw_tags(void)
 
 	switch (kasan_arg_stacktrace) {
 	case KASAN_ARG_STACKTRACE_DEFAULT:
-		/*
-		 * Default to enabling stack trace collection for
-		 * debug kernels.
-		 */
-		if (IS_ENABLED(CONFIG_DEBUG_KERNEL))
-			static_branch_enable(&kasan_flag_stacktrace);
+		/* Default to enabling stack trace collection. */
+		static_branch_enable(&kasan_flag_stacktrace);
 		break;
 	case KASAN_ARG_STACKTRACE_OFF:
 		/* Do nothing, kasan_flag_stacktrace keeps its default value. */
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Andrey Konovalov

Currently, whether the alloc/free stack traces collection is enabled by default for hardware tag-based KASAN depends on CONFIG_DEBUG_KERNEL. The intention for this dependency was to only enable collection on slow debug kernels due to a significant perf and memory impact.

As it turns out, CONFIG_DEBUG_KERNEL is not considered a debug option and is enabled on many productions kernels including Android and Ubuntu. As the result, this dependency is pointless and only complicates the code and documentation.

Having stack traces collection disabled by default would make the hardware mode work differently to to the software ones, which is confusing.

Quoted 7 lines

This change removes the dependency and enables stack traces collection by default.

Looking into the future, this default might makes sense for production kernels, assuming we implement a fast stack trace collection approach.

I'm in favor of this simplification.

The fact that CONFIG_DEBUG_KERNEL cannot be relied upon to determine if we're running a debug kernel or not is a bit unfortunate though.

Thanks!

Quoted 41 lines
---
 Documentation/dev-tools/kasan.rst | 3 +--
 mm/kasan/hw_tags.c                | 8 ++------
 2 files changed, 3 insertions(+), 8 deletions(-)
Documentation/dev-tools/kasan.rst +1 -2
index 1651d961f06a..a248ac3941be 100644
@@ -163,8 +163,7 @@ particular KASAN features.
 - ``kasan=off`` or ``=on`` controls whether KASAN is enabled (default: ``on``).
 
 - ``kasan.stacktrace=off`` or ``=on`` disables or enables alloc and free stack
-  traces collection (default: ``on`` for ``CONFIG_DEBUG_KERNEL=y``, otherwise
-  ``off``).
+  traces collection (default: ``on``).
 
 - ``kasan.fault=report`` or ``=panic`` controls whether to only print a KASAN
   report or also panic the kernel (default: ``report``).
mm/kasan/hw_tags.c +2 -7
index e529428e7a11..d558799b25b3 100644
@@ -134,12 +134,8 @@ void __init kasan_init_hw_tags(void)
 
        switch (kasan_arg_stacktrace) {
        case KASAN_ARG_STACKTRACE_DEFAULT:
-               /*
-                * Default to enabling stack trace collection for
-                * debug kernels.
-                */
-               if (IS_ENABLED(CONFIG_DEBUG_KERNEL))
-                       static_branch_enable(&kasan_flag_stacktrace);
+               /* Default to enabling stack trace collection. */
+               static_branch_enable(&kasan_flag_stacktrace);
                break;
        case KASAN_ARG_STACKTRACE_OFF:
                /* Do nothing, kasan_flag_stacktrace keeps its default value. */
--

2.30.0.478.g8a0d178c01-goog