[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200314164451.346497-1-slyfox@gentoo.org>
Date: Sat, 14 Mar 2020 16:44:51 +0000
From: Sergei Trofimovich <slyfox@...too.org>
To: linux-kernel@...r.kernel.org
Cc: Sergei Trofimovich <slyfox@...too.org>,
Jakub Jelinek <jakub@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>,
Andy Lutomirski <luto@...nel.org>, x86@...nel.org
Subject: [PATCH] x86: fix early boot crash on gcc-10
The change fixes boot failure on physical machine where kernel
is built with gcc-10 with stack-protector enabled by default:
```
Kernel panic — not syncing: stack-protector: Kernel stack is corrupted in: start_secondary+0x191/0x1a0
CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.6.0-rc5—00235—gfffb08b37df9 #139
Hardware name: Gigabyte Technology Co., Ltd. To be filled by O.E.M./H77M—D3H, BIOS F12 11/14/2013
Call Trace:
dump_stack+0x71/0xa0
panic+0x107/0x2b8
? start_secondary+0x191/0x1a0
__stack_chk_fail+0x15/0x20
start_secondary+0x191/0x1a0
secondary_startup_64+0xa4/0xb0
-—-[ end Kernel panic — not syncing: stack—protector: Kernel stack is corrupted in: start_secondary+0x191
```
This happens because `start_secondary()` is responsible for setting
up initial stack canary value in `smpboot.c`, but nothing prevents
gcc from inserting stack canary into `start_secondary()` itself
before `boot_init_stack_canary()` call.
The fix passes `-fno-stack-protector` to avoid any early stack
checks in `start_secondary()` or inlined functions into it.
Tested the change by successfully booting the machine.
A few similar crashes on VMs:
- https://bugzilla.redhat.com/show_bug.cgi?id=1796780
- http://rglinuxtech.com/?p=2694
CC: Jakub Jelinek <jakub@...hat.com>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Ingo Molnar <mingo@...hat.com>
CC: Borislav Petkov <bp@...en8.de>
CC: "H. Peter Anvin" <hpa@...or.com>
CC: Andy Lutomirski <luto@...nel.org>
CC: x86@...nel.org
Signed-off-by: Sergei Trofimovich <slyfox@...too.org>
---
arch/x86/kernel/Makefile | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 9b294c13809a..da9f4ea9bf4c 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -11,6 +11,12 @@ extra-y += vmlinux.lds
CPPFLAGS_vmlinux.lds += -U$(UTS_MACHINE)
+# smpboot's init_secondary initializes stack canary.
+# Make sure we don't emit stack checks before it's
+# initialized.
+nostackp := $(call cc-option, -fno-stack-protector)
+CFLAGS_smpboot.o := $(nostackp)
+
ifdef CONFIG_FUNCTION_TRACER
# Do not profile debug and lowlevel utilities
CFLAGS_REMOVE_tsc.o = -pg
--
2.25.1
Powered by blists - more mailing lists