1 |
commit: 69d12816ea9f46070999271a2932ee9ff8954950 |
2 |
Author: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 9 22:11:36 2020 +0000 |
4 |
Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 9 22:11:36 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=69d12816 |
7 |
|
8 |
x86: Fix early boot crash on gcc-10 |
9 |
|
10 |
Bug: https://bugs.gentoo.org/721734 |
11 |
|
12 |
Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org> |
13 |
|
14 |
0000_README | 4 + |
15 |
1700_x86-gcc-10-early-boot-crash-fix.patch | 131 +++++++++++++++++++++++++++++ |
16 |
2 files changed, 135 insertions(+) |
17 |
|
18 |
diff --git a/0000_README b/0000_README |
19 |
index c1ac1b1..ea8edd3 100644 |
20 |
--- a/0000_README |
21 |
+++ b/0000_README |
22 |
@@ -207,6 +207,10 @@ Patch: 1510_fs-enable-link-security-restrictions-by-default.patch |
23 |
From: http://sources.debian.net/src/linux/3.16.7-ckt4-3/debian/patches/debian/fs-enable-link-security-restrictions-by-default.patch/ |
24 |
Desc: Enable link security restrictions by default. |
25 |
|
26 |
+Patch: 1700_x86-gcc-10-early-boot-crash-fix.patch |
27 |
+From: https://https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/patch/?id=f670269a42bfdd2c83a1118cc3d1b475547eac22 |
28 |
+Desc: x86: Fix early boot crash on gcc-10 |
29 |
+ |
30 |
Patch: 2000_BT-Check-key-sizes-only-if-Secure-Simple-Pairing-enabled.patch |
31 |
From: https://lore.kernel.org/linux-bluetooth/20190522070540.48895-1-marcel@××××××××.org/raw |
32 |
Desc: Bluetooth: Check key sizes only when Secure Simple Pairing is enabled. See bug #686758 |
33 |
|
34 |
diff --git a/1700_x86-gcc-10-early-boot-crash-fix.patch b/1700_x86-gcc-10-early-boot-crash-fix.patch |
35 |
new file mode 100644 |
36 |
index 0000000..8cdf651 |
37 |
--- /dev/null |
38 |
+++ b/1700_x86-gcc-10-early-boot-crash-fix.patch |
39 |
@@ -0,0 +1,131 @@ |
40 |
+From f670269a42bfdd2c83a1118cc3d1b475547eac22 Mon Sep 17 00:00:00 2001 |
41 |
+From: Borislav Petkov <bp@××××.de> |
42 |
+Date: Wed, 22 Apr 2020 18:11:30 +0200 |
43 |
+Subject: x86: Fix early boot crash on gcc-10, next try |
44 |
+MIME-Version: 1.0 |
45 |
+Content-Type: text/plain; charset=UTF-8 |
46 |
+Content-Transfer-Encoding: 8bit |
47 |
+ |
48 |
+... or the odyssey of trying to disable the stack protector for the |
49 |
+function which generates the stack canary value. |
50 |
+ |
51 |
+The whole story started with Sergei reporting a boot crash with a kernel |
52 |
+built with gcc-10: |
53 |
+ |
54 |
+ Kernel panic — not syncing: stack-protector: Kernel stack is corrupted in: start_secondary |
55 |
+ CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.6.0-rc5—00235—gfffb08b37df9 #139 |
56 |
+ Hardware name: Gigabyte Technology Co., Ltd. To be filled by O.E.M./H77M—D3H, BIOS F12 11/14/2013 |
57 |
+ Call Trace: |
58 |
+ dump_stack |
59 |
+ panic |
60 |
+ ? start_secondary |
61 |
+ __stack_chk_fail |
62 |
+ start_secondary |
63 |
+ secondary_startup_64 |
64 |
+ -—-[ end Kernel panic — not syncing: stack—protector: Kernel stack is corrupted in: start_secondary |
65 |
+ |
66 |
+This happens because gcc-10 tail-call optimizes the last function call |
67 |
+in start_secondary() - cpu_startup_entry() - and thus emits a stack |
68 |
+canary check which fails because the canary value changes after the |
69 |
+boot_init_stack_canary() call. |
70 |
+ |
71 |
+To fix that, the initial attempt was to mark the one function which |
72 |
+generates the stack canary with: |
73 |
+ |
74 |
+ __attribute__((optimize("-fno-stack-protector"))) ... start_secondary(void *unused) |
75 |
+ |
76 |
+however, using the optimize attribute doesn't work cumulatively |
77 |
+as the attribute does not add to but rather replaces previously |
78 |
+supplied optimization options - roughly all -fxxx options. |
79 |
+ |
80 |
+The key one among them being -fno-omit-frame-pointer and thus leading to |
81 |
+not present frame pointer - frame pointer which the kernel needs. |
82 |
+ |
83 |
+The next attempt to prevent compilers from tail-call optimizing |
84 |
+the last function call cpu_startup_entry(), shy of carving out |
85 |
+start_secondary() into a separate compilation unit and building it with |
86 |
+-fno-stack-protector, is this one. |
87 |
+ |
88 |
+The current solution is short and sweet, and reportedly, is supported by |
89 |
+both compilers so let's see how far we'll get this time. |
90 |
+ |
91 |
+Reported-by: Sergei Trofimovich <slyfox@g.o> |
92 |
+Signed-off-by: Borislav Petkov <bp@××××.de> |
93 |
+Reviewed-by: Nick Desaulniers <ndesaulniers@××××××.com> |
94 |
+Reviewed-by: Kees Cook <keescook@××××××××.org> |
95 |
+Link: https://lkml.kernel.org/r/20200314164451.346497-1-slyfox@g.o |
96 |
+--- |
97 |
+ arch/x86/include/asm/stackprotector.h | 7 ++++++- |
98 |
+ arch/x86/kernel/smpboot.c | 8 ++++++++ |
99 |
+ arch/x86/xen/smp_pv.c | 1 + |
100 |
+ include/linux/compiler.h | 6 ++++++ |
101 |
+ 4 files changed, 21 insertions(+), 1 deletion(-) |
102 |
+ |
103 |
+diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h |
104 |
+index 91e29b6a86a5..9804a7957f4e 100644 |
105 |
+--- a/arch/x86/include/asm/stackprotector.h |
106 |
++++ b/arch/x86/include/asm/stackprotector.h |
107 |
+@@ -55,8 +55,13 @@ |
108 |
+ /* |
109 |
+ * Initialize the stackprotector canary value. |
110 |
+ * |
111 |
+- * NOTE: this must only be called from functions that never return, |
112 |
++ * NOTE: this must only be called from functions that never return |
113 |
+ * and it must always be inlined. |
114 |
++ * |
115 |
++ * In addition, it should be called from a compilation unit for which |
116 |
++ * stack protector is disabled. Alternatively, the caller should not end |
117 |
++ * with a function call which gets tail-call optimized as that would |
118 |
++ * lead to checking a modified canary value. |
119 |
+ */ |
120 |
+ static __always_inline void boot_init_stack_canary(void) |
121 |
+ { |
122 |
+diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c |
123 |
+index fe3ab9632f3b..4f275ac7830b 100644 |
124 |
+--- a/arch/x86/kernel/smpboot.c |
125 |
++++ b/arch/x86/kernel/smpboot.c |
126 |
+@@ -266,6 +266,14 @@ static void notrace start_secondary(void *unused) |
127 |
+ |
128 |
+ wmb(); |
129 |
+ cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); |
130 |
++ |
131 |
++ /* |
132 |
++ * Prevent tail call to cpu_startup_entry() because the stack protector |
133 |
++ * guard has been changed a couple of function calls up, in |
134 |
++ * boot_init_stack_canary() and must not be checked before tail calling |
135 |
++ * another function. |
136 |
++ */ |
137 |
++ prevent_tail_call_optimization(); |
138 |
+ } |
139 |
+ |
140 |
+ /** |
141 |
+diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c |
142 |
+index 8fb8a50a28b4..f2adb63b2d7c 100644 |
143 |
+--- a/arch/x86/xen/smp_pv.c |
144 |
++++ b/arch/x86/xen/smp_pv.c |
145 |
+@@ -93,6 +93,7 @@ asmlinkage __visible void cpu_bringup_and_idle(void) |
146 |
+ cpu_bringup(); |
147 |
+ boot_init_stack_canary(); |
148 |
+ cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); |
149 |
++ prevent_tail_call_optimization(); |
150 |
+ } |
151 |
+ |
152 |
+ void xen_smp_intr_free_pv(unsigned int cpu) |
153 |
+diff --git a/include/linux/compiler.h b/include/linux/compiler.h |
154 |
+index 034b0a644efc..732754d96039 100644 |
155 |
+--- a/include/linux/compiler.h |
156 |
++++ b/include/linux/compiler.h |
157 |
+@@ -356,4 +356,10 @@ static inline void *offset_to_ptr(const int *off) |
158 |
+ /* &a[0] degrades to a pointer: a different type from an array */ |
159 |
+ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) |
160 |
+ |
161 |
++/* |
162 |
++ * This is needed in functions which generate the stack canary, see |
163 |
++ * arch/x86/kernel/smpboot.c::start_secondary() for an example. |
164 |
++ */ |
165 |
++#define prevent_tail_call_optimization() asm("") |
166 |
++ |
167 |
+ #endif /* __LINUX_COMPILER_H */ |
168 |
+-- |
169 |
+cgit 1.2-0.3.lf.el7 |
170 |
+ |