Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kasan: remove redundant config option

CONFIG_KASAN_STACK and CONFIG_KASAN_STACK_ENABLE both enable KASAN stack
instrumentation, but we should only need one config, so that we remove
CONFIG_KASAN_STACK_ENABLE and make CONFIG_KASAN_STACK workable. see [1].

When enable KASAN stack instrumentation, then for gcc we could do no
prompt and default value y, and for clang prompt and default value n.

This patch fixes the following compilation warning:

include/linux/kasan.h:333:30: warning: 'CONFIG_KASAN_STACK' is not defined, evaluates to 0 [-Wundef]

[akpm@linux-foundation.org: fix merge snafu]

Link: https://bugzilla.kernel.org/show_bug.cgi?id=210221 [1]
Link: https://lkml.kernel.org/r/20210226012531.29231-1-walter-zh.wu@mediatek.com
Fixes: d9b571c885a8 ("kasan: fix KASAN_STACK dependency for HW_TAGS")
Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Suggested-by: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Walter Wu and committed by
Linus Torvalds
02c58773 5c595ac4

+18 -17
+1 -1
arch/arm64/kernel/sleep.S
··· 134 134 */ 135 135 bl cpu_do_resume 136 136 137 - #if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK 137 + #if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK) 138 138 mov x0, sp 139 139 bl kasan_unpoison_task_stack_below 140 140 #endif
+1 -1
arch/x86/kernel/acpi/wakeup_64.S
··· 115 115 movq pt_regs_r14(%rax), %r14 116 116 movq pt_regs_r15(%rax), %r15 117 117 118 - #if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK 118 + #if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK) 119 119 /* 120 120 * The suspend path may have poisoned some areas deeper in the stack, 121 121 * which we now need to unpoison.
+1 -1
include/linux/kasan.h
··· 330 330 331 331 #endif /* CONFIG_KASAN */ 332 332 333 - #if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK 333 + #if defined(CONFIG_KASAN) && defined(CONFIG_KASAN_STACK) 334 334 void kasan_unpoison_task_stack(struct task_struct *task); 335 335 #else 336 336 static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
+2 -7
lib/Kconfig.kasan
··· 138 138 139 139 endchoice 140 140 141 - config KASAN_STACK_ENABLE 141 + config KASAN_STACK 142 142 bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST 143 143 depends on KASAN_GENERIC || KASAN_SW_TAGS 144 + default y if CC_IS_GCC 144 145 help 145 146 The LLVM stack address sanitizer has a know problem that 146 147 causes excessive stack usage in a lot of functions, see ··· 154 153 but clang users can still enable it for builds without 155 154 CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe 156 155 to use and enabled by default. 157 - 158 - config KASAN_STACK 159 - int 160 - depends on KASAN_GENERIC || KASAN_SW_TAGS 161 - default 1 if KASAN_STACK_ENABLE || CC_IS_GCC 162 - default 0 163 156 164 157 config KASAN_SW_TAGS_IDENTIFY 165 158 bool "Enable memory corruption identification"
+1 -1
mm/kasan/common.c
··· 63 63 kasan_unpoison(address, size); 64 64 } 65 65 66 - #if CONFIG_KASAN_STACK 66 + #ifdef CONFIG_KASAN_STACK 67 67 /* Unpoison the entire stack for a task. */ 68 68 void kasan_unpoison_task_stack(struct task_struct *task) 69 69 {
+1 -1
mm/kasan/kasan.h
··· 231 231 const char *kasan_get_bug_type(struct kasan_access_info *info); 232 232 void kasan_metadata_fetch_row(char *buffer, void *row); 233 233 234 - #if defined(CONFIG_KASAN_GENERIC) && CONFIG_KASAN_STACK 234 + #if defined(CONFIG_KASAN_GENERIC) && defined(CONFIG_KASAN_STACK) 235 235 void kasan_print_address_stack_frame(const void *addr); 236 236 #else 237 237 static inline void kasan_print_address_stack_frame(const void *addr) { }
+1 -1
mm/kasan/report_generic.c
··· 128 128 memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); 129 129 } 130 130 131 - #if CONFIG_KASAN_STACK 131 + #ifdef CONFIG_KASAN_STACK 132 132 static bool __must_check tokenize_frame_descr(const char **frame_descr, 133 133 char *token, size_t max_tok_len, 134 134 unsigned long *value)
+8 -2
scripts/Makefile.kasan
··· 4 4 5 5 cc-param = $(call cc-option, -mllvm -$(1), $(call cc-option, --param $(1))) 6 6 7 + ifdef CONFIG_KASAN_STACK 8 + stack_enable := 1 9 + else 10 + stack_enable := 0 11 + endif 12 + 7 13 ifdef CONFIG_KASAN_GENERIC 8 14 9 15 ifdef CONFIG_KASAN_INLINE ··· 33 27 CFLAGS_KASAN := $(CFLAGS_KASAN_SHADOW) \ 34 28 $(call cc-param,asan-globals=1) \ 35 29 $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ 36 - $(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \ 30 + $(call cc-param,asan-stack=$(stack_enable)) \ 37 31 $(call cc-param,asan-instrument-allocas=1) 38 32 endif 39 33 ··· 48 42 endif 49 43 50 44 CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ 51 - $(call cc-param,hwasan-instrument-stack=$(CONFIG_KASAN_STACK)) \ 45 + $(call cc-param,hwasan-instrument-stack=$(stack_enable)) \ 52 46 $(call cc-param,hwasan-use-short-granules=0) \ 53 47 $(instrumentation_flags) 54 48
+2 -2
security/Kconfig.hardening
··· 64 64 config GCC_PLUGIN_STRUCTLEAK_BYREF 65 65 bool "zero-init structs passed by reference (strong)" 66 66 depends on GCC_PLUGINS 67 - depends on !(KASAN && KASAN_STACK=1) 67 + depends on !(KASAN && KASAN_STACK) 68 68 select GCC_PLUGIN_STRUCTLEAK 69 69 help 70 70 Zero-initialize any structures on the stack that may ··· 82 82 config GCC_PLUGIN_STRUCTLEAK_BYREF_ALL 83 83 bool "zero-init anything passed by reference (very strong)" 84 84 depends on GCC_PLUGINS 85 - depends on !(KASAN && KASAN_STACK=1) 85 + depends on !(KASAN && KASAN_STACK) 86 86 select GCC_PLUGIN_STRUCTLEAK 87 87 help 88 88 Zero-initialize any stack variables that may be passed