Skip to content

Commit d788081

Browse files
committed
idle: Add the stack canary init to cpu_startup_entry()
Moving x86 to the generic idle implementation (commit 7d1a941 "x86: Use generic idle loop") wreckaged the stack protector. I stupidly missed that boot_init_stack_canary() must be inlined from a function which never returns, but I put that call into arch_cpu_idle_prepare() which of course returns. I pondered to play tricks with arch_cpu_idle_prepare() first, but then I noticed, that the other archs which have implemented the stackprotector (ARM and SH) do not initialize the canary for the non-boot cpus. So I decided to move the boot_init_stack_canary() call into cpu_startup_entry() ifdeffed with an CONFIG_X86 for now. This #ifdef is just a temporary measure as I don't want to inflict the boot_init_stack_canary() call on ARM and SH that late in the cycle. I'll queue a patch for 3.11 which removes the #ifdef if the ARM/SH maintainers have no objection. Reported-by: Wouter van Kesteren <woutershep@gmail.com> Cc: x86@kernel.org Cc: Russell King <linux@arm.linux.org.uk> Cc: Paul Mundt <lethal@linux-sh.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent c778879 commit d788081

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

arch/x86/kernel/process.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,6 @@ void exit_idle(void)
277277
}
278278
#endif
279279

280-
void arch_cpu_idle_prepare(void)
281-
{
282-
/*
283-
* If we're the non-boot CPU, nothing set the stack canary up
284-
* for us. CPU0 already has it initialized but no harm in
285-
* doing it again. This is a good place for updating it, as
286-
* we wont ever return from this function (so the invalid
287-
* canaries already on the stack wont ever trigger).
288-
*/
289-
boot_init_stack_canary();
290-
}
291-
292280
void arch_cpu_idle_enter(void)
293281
{
294282
local_touch_nmi();

kernel/cpu/idle.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/cpu.h>
66
#include <linux/tick.h>
77
#include <linux/mm.h>
8+
#include <linux/stackprotector.h>
89

910
#include <asm/tlb.h>
1011

@@ -112,6 +113,21 @@ static void cpu_idle_loop(void)
112113

113114
void cpu_startup_entry(enum cpuhp_state state)
114115
{
116+
/*
117+
* This #ifdef needs to die, but it's too late in the cycle to
118+
* make this generic (arm and sh have never invoked the canary
119+
* init for the non boot cpus!). Will be fixed in 3.11
120+
*/
121+
#ifdef CONFIG_X86
122+
/*
123+
* If we're the non-boot CPU, nothing set the stack canary up
124+
* for us. The boot CPU already has it initialized but no harm
125+
* in doing it again. This is a good place for updating it, as
126+
* we wont ever return from this function (so the invalid
127+
* canaries already on the stack wont ever trigger).
128+
*/
129+
boot_init_stack_canary();
130+
#endif
115131
current_set_polling();
116132
arch_cpu_idle_prepare();
117133
cpu_idle_loop();

0 commit comments

Comments
 (0)