Skip to contentSkip to conversation

x86/asm: Make sure verify_cpu() has a good stack

PATCH New Borislav Petkov 2 participants 2 messages Mar 31, 2016 – Apr 13, 2016

Subsystems (2)
lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/asm: Make sure verify_cpu() has a good stack

From: Borislav Petkov <[email protected]>

04633df0c43d ("x86/cpu: Call verify_cpu() after having entered long mode too") added the call to verify_cpu() for sanitizing CPU configuration.

The latter uses the stack minimally and it can happen that we land in startup_64() directly from a 64-bit bootloader. Then we want to use our own, known good stack.

Do that.

APs don't need this as the trampoline sets up a stack for them.

Cc Brian Gerst <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Mika Penttilä <[email protected]>
---
 arch/x86/kernel/head_64.S         | 8 ++++++++
 include/asm-generic/vmlinux.lds.h | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)
arch/x86/kernel/head_64.S +8 -0
index 22fbf9df61bb..e69742517a54 100644
@@ -64,6 +64,14 @@ startup_64:
 	 * tables and then reload them.
 	 */
 
+	/*
+	 * Setup stack for verify_cpu(). "-8" because stack_start is defined
+	 * this way, see below. Our best guess is a NULL ptr for stack
+	 * termination heuristics and we don't want to break anything which
+	 * might depend on it (kgdb, ...).
+	 */
+	leaq	(__end_init_task - 8)(%rip), %rsp
+
 	/* Sanitize CPU configuration */
 	call verify_cpu
 
include/asm-generic/vmlinux.lds.h +3 -1
index 339125bb4d2c..6a67ab94b553 100644
@@ -245,7 +245,9 @@
 
 #define INIT_TASK_DATA(align)						\
 	. = ALIGN(align);						\
-	*(.data..init_task)
+	VMLINUX_SYMBOL(__start_init_task) = .;				\
+	*(.data..init_task)						\
+	VMLINUX_SYMBOL(__end_init_task) = .;
 
 /*
  * Read only Data
Signature · 1 line
2.7.3
#1 lore raw
x86/asm: Make sure verify_cpu() has a good stack
Commit-ID:  91ed140d6c1e168b11bbbddac4f6066f40a0c6b5
Gitweb:     http://git.kernel.org/tip/91ed140d6c1e168b11bbbddac4f6066f40a0c6b5
Author:     Borislav Petkov <[email protected]>
AuthorDate: Thu, 31 Mar 2016 16:21:02 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:52:19 +0200

x86/asm: Make sure verify_cpu() has a good stack

04633df0c43d ("x86/cpu: Call verify_cpu() after having entered long mode too") added the call to verify_cpu() for sanitizing CPU configuration.

The latter uses the stack minimally and it can happen that we land in startup_64() directly from a 64-bit bootloader. Then we want to use our own, known good stack.

Do that.

APs don't need this as the trampoline sets up a stack for them.

---
 arch/x86/kernel/head_64.S         | 8 ++++++++
 include/asm-generic/vmlinux.lds.h | 4 +++-
 2 files changed, 11 insertions(+), 1 deletion(-)
arch/x86/kernel/head_64.S +8 -0
index 3de91a7..5df831e 100644
@@ -65,6 +65,14 @@ startup_64:
 	 * tables and then reload them.
 	 */
 
+	/*
+	 * Setup stack for verify_cpu(). "-8" because stack_start is defined
+	 * this way, see below. Our best guess is a NULL ptr for stack
+	 * termination heuristics and we don't want to break anything which
+	 * might depend on it (kgdb, ...).
+	 */
+	leaq	(__end_init_task - 8)(%rip), %rsp
+
 	/* Sanitize CPU configuration */
 	call verify_cpu
 
include/asm-generic/vmlinux.lds.h +3 -1
index 339125b..6a67ab9 100644
@@ -245,7 +245,9 @@
 
 #define INIT_TASK_DATA(align)						\
 	. = ALIGN(align);						\
-	*(.data..init_task)
+	VMLINUX_SYMBOL(__start_init_task) = .;				\
+	*(.data..init_task)						\
+	VMLINUX_SYMBOL(__end_init_task) = .;
 
 /*
  * Read only Data