@@ -244,4 +244,32 @@ config KASAN_SW_TAGS_DENSE
ARCH_HAS_KASAN_SW_TAGS_DENSE is needed for this option since the
special tag macros need to be properly set for 4-bit wide tags.
+choice
+ prompt "KASAN operation mode"
+ default KASAN_OPERATION_DEBUG
+ help
+ Choose between the mitigation or debug operation modes.
+
+ The first one disables stacktrace saving and enables panic on error.
+ Faster memory allocation but less information. The second one is the
+ default where KASAN operates with full functionality.
+
+config KASAN_OPERATION_DEBUG
+ bool "Debug operation mode"
+ depends on KASAN
+ help
+ The default mode. Full functionality and all boot parameters
+ available.
+
+config KASAN_OPERATION_MITIGATION
+ bool "Mitigation operation mode"
+ depends on KASAN
+ help
+ Operation mode dedicated at faster operation at the cost of less
+ information collection. Disables stacktrace saving for faster
+ allocations and forces panic on KASAN error to mitigate malicious
+ attacks.
+
+endchoice
+
endif # KASAN
@@ -47,7 +47,11 @@ enum kasan_arg_fault {
KASAN_ARG_FAULT_PANIC_ON_WRITE,
};
+#ifdef CONFIG_KASAN_OPERATION_MITIGATION
+static enum kasan_arg_fault kasan_arg_fault __ro_after_init = KASAN_ARG_FAULT_PANIC;
+#else
static enum kasan_arg_fault kasan_arg_fault __ro_after_init = KASAN_ARG_FAULT_DEFAULT;
+#endif
/* kasan.fault=report/panic */
static int __init early_kasan_fault(char *arg)
@@ -78,6 +78,11 @@ early_param("kasan.stack_ring_size", early_kasan_flag_stack_ring_size);
void __init kasan_init_tags(void)
{
+ if (IS_ENABLED(CONFIG_KASAN_OPERATION_MITIGATION)) {
+ static_branch_disable(&kasan_flag_stacktrace);
+ return;
+ }
+
switch (kasan_arg_stacktrace) {
case KASAN_ARG_STACKTRACE_DEFAULT:
/* Default is specified by kasan_flag_stacktrace definition. */
With smaller memory footprint KASAN could be used in production systems. One problem is that saving stacktraces slowes memory allocation substantially - with KASAN enabled up to 90% of time spent on kmalloc() is spent on saving the stacktrace. Add mitigation mode to allow the option for running KASAN focused on performance and security. In mitigation mode disable saving stacktraces and set fault mode to always panic on KASAN error as a security mechanism. Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com> --- lib/Kconfig.kasan | 28 ++++++++++++++++++++++++++++ mm/kasan/report.c | 4 ++++ mm/kasan/tags.c | 5 +++++ 3 files changed, 37 insertions(+)