x86/asm: Make sure verify_cpu() has a good stack
authorBorislav Petkov <bp@suse.de>
Thu, 31 Mar 2016 14:21:02 +0000 (16:21 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 13 Apr 2016 09:52:19 +0000 (11:52 +0200)
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.

Reported-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mika Penttilä <mika.penttila@nextfour.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1459434062-31055-1-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/head_64.S
include/asm-generic/vmlinux.lds.h

index 3de91a7e6c99c7e324ee62f9514ac08edc86799d..5df831ef1442f36c5ee0ac00447a2505216d1a26 100644 (file)
@@ -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
 
index 339125bb4d2cf919669677c5d8edc900157bcc50..6a67ab94b553363934bc9c2e07eb12d6c8a977f7 100644 (file)
 
 #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