Skip to content

Commit 7771bdb

Browse files
aryabinintorvalds
authored andcommitted
kasan: remove use after scope bugs detection.
Use after scope bugs detector seems to be almost entirely useless for the linux kernel. It exists over two years, but I've seen only one valid bug so far [1]. And the bug was fixed before it has been reported. There were some other use-after-scope reports, but they were false-positives due to different reasons like incompatibility with structleak plugin. This feature significantly increases stack usage, especially with GCC < 9 version, and causes a 32K stack overflow. It probably adds performance penalty too. Given all that, let's remove use-after-scope detector entirely. While preparing this patch I've noticed that we mistakenly enable use-after-scope detection for clang compiler regardless of CONFIG_KASAN_EXTRA setting. This is also fixed now. [1] http://lkml.kernel.org/r/<[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Andrey Ryabinin <[email protected]> Acked-by: Will Deacon <[email protected]> [arm64] Cc: Qian Cai <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Catalin Marinas <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 46612b7 commit 7771bdb

File tree

9 files changed

+0
-73
lines changed

9 files changed

+0
-73
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@
8080
*/
8181
#ifdef CONFIG_KASAN
8282
#define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
83-
#ifdef CONFIG_KASAN_EXTRA
84-
#define KASAN_THREAD_SHIFT 2
85-
#else
8683
#define KASAN_THREAD_SHIFT 1
87-
#endif /* CONFIG_KASAN_EXTRA */
8884
#else
8985
#define KASAN_SHADOW_SIZE (0)
9086
#define KASAN_THREAD_SHIFT 0

lib/Kconfig.debug

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ config ENABLE_MUST_CHECK
222222
config FRAME_WARN
223223
int "Warn for stack frames larger than (needs gcc 4.4)"
224224
range 0 8192
225-
default 3072 if KASAN_EXTRA
226225
default 2048 if GCC_PLUGIN_LATENT_ENTROPY
227226
default 1280 if (!64BIT && PARISC)
228227
default 1024 if (!64BIT && !PARISC)

lib/Kconfig.kasan

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ config KASAN_SW_TAGS
7878

7979
endchoice
8080

81-
config KASAN_EXTRA
82-
bool "KASAN: extra checks"
83-
depends on KASAN_GENERIC && DEBUG_KERNEL && !COMPILE_TEST
84-
help
85-
This enables further checks in generic KASAN, for now it only
86-
includes the address-use-after-scope check that can lead to
87-
excessive kernel stack usage, frame size warnings and longer
88-
compile time.
89-
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715
90-
9181
choice
9282
prompt "Instrumentation type"
9383
depends on KASAN

lib/test_kasan.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -480,29 +480,6 @@ static noinline void __init copy_user_test(void)
480480
kfree(kmem);
481481
}
482482

483-
static noinline void __init use_after_scope_test(void)
484-
{
485-
volatile char *volatile p;
486-
487-
pr_info("use-after-scope on int\n");
488-
{
489-
int local = 0;
490-
491-
p = (char *)&local;
492-
}
493-
p[0] = 1;
494-
p[3] = 1;
495-
496-
pr_info("use-after-scope on array\n");
497-
{
498-
char local[1024] = {0};
499-
500-
p = local;
501-
}
502-
p[0] = 1;
503-
p[1023] = 1;
504-
}
505-
506483
static noinline void __init kasan_alloca_oob_left(void)
507484
{
508485
volatile int i = 10;
@@ -682,7 +659,6 @@ static int __init kmalloc_tests_init(void)
682659
kasan_alloca_oob_right();
683660
ksize_unpoisons_memory();
684661
copy_user_test();
685-
use_after_scope_test();
686662
kmem_cache_double_free();
687663
kmem_cache_invalid_free();
688664
kasan_memchr();

mm/kasan/generic.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,6 @@ EXPORT_SYMBOL(__asan_storeN_noabort);
275275
void __asan_handle_no_return(void) {}
276276
EXPORT_SYMBOL(__asan_handle_no_return);
277277

278-
/* Emitted by compiler to poison large objects when they go out of scope. */
279-
void __asan_poison_stack_memory(const void *addr, size_t size)
280-
{
281-
/*
282-
* Addr is KASAN_SHADOW_SCALE_SIZE-aligned and the object is surrounded
283-
* by redzones, so we simply round up size to simplify logic.
284-
*/
285-
kasan_poison_shadow(addr, round_up(size, KASAN_SHADOW_SCALE_SIZE),
286-
KASAN_USE_AFTER_SCOPE);
287-
}
288-
EXPORT_SYMBOL(__asan_poison_stack_memory);
289-
290-
/* Emitted by compiler to unpoison large objects when they go into scope. */
291-
void __asan_unpoison_stack_memory(const void *addr, size_t size)
292-
{
293-
kasan_unpoison_shadow(addr, size);
294-
}
295-
EXPORT_SYMBOL(__asan_unpoison_stack_memory);
296-
297278
/* Emitted by compiler to poison alloca()ed objects. */
298279
void __asan_alloca_poison(unsigned long addr, size_t size)
299280
{

mm/kasan/generic_report.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info)
8282
case KASAN_KMALLOC_FREE:
8383
bug_type = "use-after-free";
8484
break;
85-
case KASAN_USE_AFTER_SCOPE:
86-
bug_type = "use-after-scope";
87-
break;
8885
case KASAN_ALLOCA_LEFT:
8986
case KASAN_ALLOCA_RIGHT:
9087
bug_type = "alloca-out-of-bounds";

mm/kasan/kasan.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#define KASAN_STACK_MID 0xF2
3535
#define KASAN_STACK_RIGHT 0xF3
3636
#define KASAN_STACK_PARTIAL 0xF4
37-
#define KASAN_USE_AFTER_SCOPE 0xF8
3837

3938
/*
4039
* alloca redzone shadow values
@@ -187,8 +186,6 @@ void __asan_unregister_globals(struct kasan_global *globals, size_t size);
187186
void __asan_loadN(unsigned long addr, size_t size);
188187
void __asan_storeN(unsigned long addr, size_t size);
189188
void __asan_handle_no_return(void);
190-
void __asan_poison_stack_memory(const void *addr, size_t size);
191-
void __asan_unpoison_stack_memory(const void *addr, size_t size);
192189
void __asan_alloca_poison(unsigned long addr, size_t size);
193190
void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
194191

scripts/Makefile.kasan

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@ else
2727
$(call cc-param,asan-globals=1) \
2828
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
2929
$(call cc-param,asan-stack=$(CONFIG_KASAN_STACK)) \
30-
$(call cc-param,asan-use-after-scope=1) \
3130
$(call cc-param,asan-instrument-allocas=1)
3231
endif
3332

34-
ifdef CONFIG_KASAN_EXTRA
35-
CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
36-
endif
37-
3833
endif # CONFIG_KASAN_GENERIC
3934

4035
ifdef CONFIG_KASAN_SW_TAGS

scripts/gcc-plugins/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ config GCC_PLUGIN_LATENT_ENTROPY
6868

6969
config GCC_PLUGIN_STRUCTLEAK
7070
bool "Force initialization of variables containing userspace addresses"
71-
# Currently STRUCTLEAK inserts initialization out of live scope of
72-
# variables from KASAN point of view. This leads to KASAN false
73-
# positive reports. Prohibit this combination for now.
74-
depends on !KASAN_EXTRA
7571
help
7672
This plugin zero-initializes any structures containing a
7773
__user attribute. This can prevent some classes of information

0 commit comments

Comments
 (0)