Skip to content

Commit 977e4be

Browse files
chleroyIngo Molnar
authored andcommitted
x86/stackprotector: Remove the call to boot_init_stack_canary() from cpu_startup_entry()
The following commit: d788081 ("idle: Add the stack canary init to cpu_startup_entry()") ... added an x86 specific boot_init_stack_canary() call to the generic cpu_startup_entry() as a temporary hack, with the intention to remove the #ifdef CONFIG_X86 later. More than 5 years later let's finally realize that plan! :-) While implementing stack protector support for PowerPC, we found that calling boot_init_stack_canary() is also needed for PowerPC which uses per task (TLS) stack canary like the X86. However, calling boot_init_stack_canary() would break architectures using a global stack canary (ARM, SH, MIPS and XTENSA). Instead of modifying the #ifdef CONFIG_X86 to an even messier: #if defined(CONFIG_X86) || defined(CONFIG_PPC) PowerPC implemented the call to boot_init_stack_canary() in the function calling cpu_startup_entry(). Let's try the same cleanup on the x86 side as well. On x86 we have two functions calling cpu_startup_entry(): - start_secondary() - cpu_bringup_and_idle() start_secondary() already calls boot_init_stack_canary(), so it's good, and this patch adds the call to boot_init_stack_canary() in cpu_bringup_and_idle(). I.e. now x86 catches up to the rest of the world and the ugly init sequence in init/main.c can be removed from cpu_startup_entry(). As a final benefit we can also remove the <linux/stackprotector.h> dependency from <linux/sched.h>. [ mingo: Improved the changelog a bit, added language explaining x86 borkage and sched.h change. ] Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Reviewed-by: Juergen Gross <jgross@suse.com> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linuxppc-dev@lists.ozlabs.org Cc: xen-devel@lists.xenproject.org Link: http://lkml.kernel.org/r/20181020072649.5B59310483E@pc16082vm.idsi0.si.c-s.fr Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1620414 commit 977e4be

File tree

3 files changed

+2
-16
lines changed

3 files changed

+2
-16
lines changed

arch/x86/xen/smp_pv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/tick.h>
2323
#include <linux/nmi.h>
2424
#include <linux/cpuhotplug.h>
25+
#include <linux/stackprotector.h>
2526

2627
#include <asm/paravirt.h>
2728
#include <asm/desc.h>
@@ -88,6 +89,7 @@ static void cpu_bringup(void)
8889
asmlinkage __visible void cpu_bringup_and_idle(void)
8990
{
9091
cpu_bringup();
92+
boot_init_stack_canary();
9193
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
9294
}
9395

kernel/sched/idle.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,6 @@ EXPORT_SYMBOL_GPL(play_idle);
347347

348348
void cpu_startup_entry(enum cpuhp_state state)
349349
{
350-
/*
351-
* This #ifdef needs to die, but it's too late in the cycle to
352-
* make this generic (ARM and SH have never invoked the canary
353-
* init for the non boot CPUs!). Will be fixed in 3.11
354-
*/
355-
#ifdef CONFIG_X86
356-
/*
357-
* If we're the non-boot CPU, nothing set the stack canary up
358-
* for us. The boot CPU already has it initialized but no harm
359-
* in doing it again. This is a good place for updating it, as
360-
* we wont ever return from this function (so the invalid
361-
* canaries already on the stack wont ever trigger).
362-
*/
363-
boot_init_stack_canary();
364-
#endif
365350
arch_cpu_idle_prepare();
366351
cpuhp_online_idle(state);
367352
while (1)

kernel/sched/sched.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#include <linux/profile.h>
5757
#include <linux/rcupdate_wait.h>
5858
#include <linux/security.h>
59-
#include <linux/stackprotector.h>
6059
#include <linux/stop_machine.h>
6160
#include <linux/suspend.h>
6261
#include <linux/swait.h>

0 commit comments

Comments
 (0)