提交 363eeef5 编写于 作者: A Andrey Ryabinin 提交者: Xie XiuQi

kasan: remove use after scope bugs detection.

mainline inclusion
from mainline-v5.0
commit 7771bdbbfd3d6f204631b6fd9e1bbc30cd15918e
category: bugfix
bugzilla: 10979
CVE: NA

------------------------------------------------

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/<20171129052106.rhgbjhhis53hkgfn@wfg-t540p.sh.intel.com>

Link: http://lkml.kernel.org/r/20190111185842.13978-1-aryabinin@virtuozzo.comSigned-off-by: NAndrey Ryabinin <aryabinin@virtuozzo.com>
Acked-by: Will Deacon <will.deacon@arm.com>		[arm64]
Cc: Qian Cai <cai@lca.pw>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nzhong jiang <zhongjiang@huawei.com>
Reviewed-by: NJing Xiangfeng <jingxiangfeng@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 8eb04a7a
...@@ -82,11 +82,7 @@ ...@@ -82,11 +82,7 @@
#ifdef CONFIG_KASAN #ifdef CONFIG_KASAN
#define KASAN_SHADOW_SCALE_SHIFT 3 #define KASAN_SHADOW_SCALE_SHIFT 3
#define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT)) #define KASAN_SHADOW_SIZE (UL(1) << (VA_BITS - KASAN_SHADOW_SCALE_SHIFT))
#ifdef CONFIG_KASAN_EXTRA
#define KASAN_THREAD_SHIFT 2
#else
#define KASAN_THREAD_SHIFT 1 #define KASAN_THREAD_SHIFT 1
#endif /* CONFIG_KASAN_EXTRA */
#else #else
#define KASAN_SHADOW_SIZE (0) #define KASAN_SHADOW_SIZE (0)
#define KASAN_THREAD_SHIFT 0 #define KASAN_THREAD_SHIFT 0
......
...@@ -222,7 +222,6 @@ config ENABLE_MUST_CHECK ...@@ -222,7 +222,6 @@ config ENABLE_MUST_CHECK
config FRAME_WARN config FRAME_WARN
int "Warn for stack frames larger than (needs gcc 4.4)" int "Warn for stack frames larger than (needs gcc 4.4)"
range 0 8192 range 0 8192
default 3072 if KASAN_EXTRA
default 2048 if GCC_PLUGIN_LATENT_ENTROPY default 2048 if GCC_PLUGIN_LATENT_ENTROPY
default 1280 if (!64BIT && PARISC) default 1280 if (!64BIT && PARISC)
default 1024 if (!64BIT && !PARISC) default 1024 if (!64BIT && !PARISC)
......
...@@ -21,17 +21,6 @@ config KASAN ...@@ -21,17 +21,6 @@ config KASAN
Currently CONFIG_KASAN doesn't work with CONFIG_DEBUG_SLAB Currently CONFIG_KASAN doesn't work with CONFIG_DEBUG_SLAB
(the resulting kernel does not boot). (the resulting kernel does not boot).
config KASAN_EXTRA
bool "KAsan: extra checks"
depends on KASAN && DEBUG_KERNEL && !COMPILE_TEST
help
This enables further checks in the kernel address sanitizer, for now
it only includes the address-use-after-scope check that can lead
to excessive kernel stack usage, frame size warnings and longer
compile time.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 has more
choice choice
prompt "Instrumentation type" prompt "Instrumentation type"
depends on KASAN depends on KASAN
......
...@@ -480,29 +480,6 @@ static noinline void __init copy_user_test(void) ...@@ -480,29 +480,6 @@ static noinline void __init copy_user_test(void)
kfree(kmem); kfree(kmem);
} }
static noinline void __init use_after_scope_test(void)
{
volatile char *volatile p;
pr_info("use-after-scope on int\n");
{
int local = 0;
p = (char *)&local;
}
p[0] = 1;
p[3] = 1;
pr_info("use-after-scope on array\n");
{
char local[1024] = {0};
p = local;
}
p[0] = 1;
p[1023] = 1;
}
static noinline void __init kasan_alloca_oob_left(void) static noinline void __init kasan_alloca_oob_left(void)
{ {
volatile int i = 10; volatile int i = 10;
...@@ -682,7 +659,6 @@ static int __init kmalloc_tests_init(void) ...@@ -682,7 +659,6 @@ static int __init kmalloc_tests_init(void)
kasan_alloca_oob_right(); kasan_alloca_oob_right();
ksize_unpoisons_memory(); ksize_unpoisons_memory();
copy_user_test(); copy_user_test();
use_after_scope_test();
kmem_cache_double_free(); kmem_cache_double_free();
kmem_cache_invalid_free(); kmem_cache_invalid_free();
kasan_memchr(); kasan_memchr();
......
...@@ -724,25 +724,6 @@ EXPORT_SYMBOL(__asan_storeN_noabort); ...@@ -724,25 +724,6 @@ EXPORT_SYMBOL(__asan_storeN_noabort);
void __asan_handle_no_return(void) {} void __asan_handle_no_return(void) {}
EXPORT_SYMBOL(__asan_handle_no_return); EXPORT_SYMBOL(__asan_handle_no_return);
/* Emitted by compiler to poison large objects when they go out of scope. */
void __asan_poison_stack_memory(const void *addr, size_t size)
{
/*
* Addr is KASAN_SHADOW_SCALE_SIZE-aligned and the object is surrounded
* by redzones, so we simply round up size to simplify logic.
*/
kasan_poison_shadow(addr, round_up(size, KASAN_SHADOW_SCALE_SIZE),
KASAN_USE_AFTER_SCOPE);
}
EXPORT_SYMBOL(__asan_poison_stack_memory);
/* Emitted by compiler to unpoison large objects when they go into scope. */
void __asan_unpoison_stack_memory(const void *addr, size_t size)
{
kasan_unpoison_shadow(addr, size);
}
EXPORT_SYMBOL(__asan_unpoison_stack_memory);
/* Emitted by compiler to poison alloca()ed objects. */ /* Emitted by compiler to poison alloca()ed objects. */
void __asan_alloca_poison(unsigned long addr, size_t size) void __asan_alloca_poison(unsigned long addr, size_t size)
{ {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#define KASAN_STACK_MID 0xF2 #define KASAN_STACK_MID 0xF2
#define KASAN_STACK_RIGHT 0xF3 #define KASAN_STACK_RIGHT 0xF3
#define KASAN_STACK_PARTIAL 0xF4 #define KASAN_STACK_PARTIAL 0xF4
#define KASAN_USE_AFTER_SCOPE 0xF8
/* /*
* alloca redzone shadow values * alloca redzone shadow values
...@@ -130,8 +129,6 @@ void __asan_unregister_globals(struct kasan_global *globals, size_t size); ...@@ -130,8 +129,6 @@ void __asan_unregister_globals(struct kasan_global *globals, size_t size);
void __asan_loadN(unsigned long addr, size_t size); void __asan_loadN(unsigned long addr, size_t size);
void __asan_storeN(unsigned long addr, size_t size); void __asan_storeN(unsigned long addr, size_t size);
void __asan_handle_no_return(void); void __asan_handle_no_return(void);
void __asan_poison_stack_memory(const void *addr, size_t size);
void __asan_unpoison_stack_memory(const void *addr, size_t size);
void __asan_alloca_poison(unsigned long addr, size_t size); void __asan_alloca_poison(unsigned long addr, size_t size);
void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom); void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
......
...@@ -99,9 +99,6 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info) ...@@ -99,9 +99,6 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info)
case KASAN_KMALLOC_FREE: case KASAN_KMALLOC_FREE:
bug_type = "use-after-free"; bug_type = "use-after-free";
break; break;
case KASAN_USE_AFTER_SCOPE:
bug_type = "use-after-scope";
break;
case KASAN_ALLOCA_LEFT: case KASAN_ALLOCA_LEFT:
case KASAN_ALLOCA_RIGHT: case KASAN_ALLOCA_RIGHT:
bug_type = "alloca-out-of-bounds"; bug_type = "alloca-out-of-bounds";
......
...@@ -32,16 +32,11 @@ else ...@@ -32,16 +32,11 @@ else
$(call cc-param,asan-globals=1) \ $(call cc-param,asan-globals=1) \
$(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \ $(call cc-param,asan-instrumentation-with-call-threshold=$(call_threshold)) \
$(call cc-param,asan-stack=1) \ $(call cc-param,asan-stack=1) \
$(call cc-param,asan-use-after-scope=1) \
$(call cc-param,asan-instrument-allocas=1) $(call cc-param,asan-instrument-allocas=1)
endif endif
endif endif
ifdef CONFIG_KASAN_EXTRA
CFLAGS_KASAN += $(call cc-option, -fsanitize-address-use-after-scope)
endif
CFLAGS_KASAN_NOSANITIZE := -fno-builtin CFLAGS_KASAN_NOSANITIZE := -fno-builtin
endif endif
...@@ -68,10 +68,6 @@ config GCC_PLUGIN_LATENT_ENTROPY ...@@ -68,10 +68,6 @@ config GCC_PLUGIN_LATENT_ENTROPY
config GCC_PLUGIN_STRUCTLEAK config GCC_PLUGIN_STRUCTLEAK
bool "Force initialization of variables containing userspace addresses" bool "Force initialization of variables containing userspace addresses"
# Currently STRUCTLEAK inserts initialization out of live scope of
# variables from KASAN point of view. This leads to KASAN false
# positive reports. Prohibit this combination for now.
depends on !KASAN_EXTRA
help help
This plugin zero-initializes any structures containing a This plugin zero-initializes any structures containing a
__user attribute. This can prevent some classes of information __user attribute. This can prevent some classes of information
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册