]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.20/x86_64-increase-stack-size-for-kasan_extra.patch
patches for 4.20
[thirdparty/kernel/stable-queue.git] / queue-4.20 / x86_64-increase-stack-size-for-kasan_extra.patch
1 From 67fd2fd35761d6bb8dcebe5070960c2f0baaef69 Mon Sep 17 00:00:00 2001
2 From: Qian Cai <cai@lca.pw>
3 Date: Fri, 1 Feb 2019 14:20:20 -0800
4 Subject: x86_64: increase stack size for KASAN_EXTRA
5
6 [ Upstream commit a8e911d13540487942d53137c156bd7707f66e5d ]
7
8 If the kernel is configured with KASAN_EXTRA, the stack size is
9 increasted significantly because this option sets "-fstack-reuse" to
10 "none" in GCC [1]. As a result, it triggers stack overrun quite often
11 with 32k stack size compiled using GCC 8. For example, this reproducer
12
13 https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/madvise/madvise06.c
14
15 triggers a "corrupted stack end detected inside scheduler" very reliably
16 with CONFIG_SCHED_STACK_END_CHECK enabled.
17
18 There are just too many functions that could have a large stack with
19 KASAN_EXTRA due to large local variables that have been called over and
20 over again without being able to reuse the stacks. Some noticiable ones
21 are
22
23 size
24 7648 shrink_page_list
25 3584 xfs_rmap_convert
26 3312 migrate_page_move_mapping
27 3312 dev_ethtool
28 3200 migrate_misplaced_transhuge_page
29 3168 copy_process
30
31 There are other 49 functions are over 2k in size while compiling kernel
32 with "-Wframe-larger-than=" even with a related minimal config on this
33 machine. Hence, it is too much work to change Makefiles for each object
34 to compile without "-fsanitize-address-use-after-scope" individually.
35
36 [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81715#c23
37
38 Although there is a patch in GCC 9 to help the situation, GCC 9 probably
39 won't be released in a few months and then it probably take another
40 6-month to 1-year for all major distros to include it as a default.
41 Hence, the stack usage with KASAN_EXTRA can be revisited again in 2020
42 when GCC 9 is everywhere. Until then, this patch will help users avoid
43 stack overrun.
44
45 This has already been fixed for arm64 for the same reason via
46 6e8830674ea ("arm64: kasan: Increase stack size for KASAN_EXTRA").
47
48 Link: http://lkml.kernel.org/r/20190109215209.2903-1-cai@lca.pw
49 Signed-off-by: Qian Cai <cai@lca.pw>
50 Cc: Thomas Gleixner <tglx@linutronix.de>
51 Cc: Ingo Molnar <mingo@redhat.com>
52 Cc: Borislav Petkov <bp@alien8.de>
53 Cc: "H. Peter Anvin" <hpa@zytor.com>
54 Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
55 Cc: Alexander Potapenko <glider@google.com>
56 Cc: Dmitry Vyukov <dvyukov@google.com>
57 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
58 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
59 Signed-off-by: Sasha Levin <sashal@kernel.org>
60 ---
61 arch/x86/include/asm/page_64_types.h | 4 ++++
62 1 file changed, 4 insertions(+)
63
64 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
65 index 8f657286d599a..0ce558a8150d3 100644
66 --- a/arch/x86/include/asm/page_64_types.h
67 +++ b/arch/x86/include/asm/page_64_types.h
68 @@ -7,7 +7,11 @@
69 #endif
70
71 #ifdef CONFIG_KASAN
72 +#ifdef CONFIG_KASAN_EXTRA
73 +#define KASAN_STACK_ORDER 2
74 +#else
75 #define KASAN_STACK_ORDER 1
76 +#endif
77 #else
78 #define KASAN_STACK_ORDER 0
79 #endif
80 --
81 2.19.1
82