Skip to content

Commit b6aedde

Browse files
committed
powerpc: Fix stack protector crashes on CPU hotplug
Recently in commit 7241d26 ("powerpc/64: properly initialise the stackprotector canary on SMP.") we fixed a crash with stack protector on SMP by initialising the stack canary in cpu_idle_thread_init(). But this can also causes crashes, when a CPU comes back online after being offline: Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: pnv_smp_cpu_kill_self+0x2a0/0x2b0 CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.19.0-rc3-gcc-7.3.1-00168-g4ffe713b7587 torvalds#94 Call Trace: dump_stack+0xb0/0xf4 (unreliable) panic+0x144/0x328 __stack_chk_fail+0x2c/0x30 pnv_smp_cpu_kill_self+0x2a0/0x2b0 cpu_die+0x48/0x70 arch_cpu_idle_dead+0x20/0x40 do_idle+0x274/0x390 cpu_startup_entry+0x38/0x50 start_secondary+0x5e4/0x600 start_secondary_prolog+0x10/0x14 Looking at the stack we see that the canary value in the stack frame doesn't match the canary in the task/paca. That is because we have reinitialised the task/paca value, but then the CPU coming online has returned into a function using the old canary value. That causes the comparison to fail. Instead we can call boot_init_stack_canary() from start_secondary() which never returns. This is essentially what the generic code does in cpu_startup_entry() under #ifdef X86, we should make that non-x86 specific in a future patch. Fixes: 7241d26 ("powerpc/64: properly initialise the stackprotector canary on SMP.") Reported-by: Joel Stanley <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Reviewed-by: Christophe Leroy <[email protected]>
1 parent daf00ae commit b6aedde

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Diff for: arch/powerpc/kernel/smp.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/profile.h>
3636
#include <linux/processor.h>
3737
#include <linux/random.h>
38+
#include <linux/stackprotector.h>
3839

3940
#include <asm/ptrace.h>
4041
#include <linux/atomic.h>
@@ -1014,16 +1015,9 @@ static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
10141015
{
10151016
struct thread_info *ti = task_thread_info(idle);
10161017

1017-
#ifdef CONFIG_STACKPROTECTOR
1018-
idle->stack_canary = get_random_canary();
1019-
#endif
1020-
10211018
#ifdef CONFIG_PPC64
10221019
paca_ptrs[cpu]->__current = idle;
10231020
paca_ptrs[cpu]->kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
1024-
#ifdef CONFIG_STACKPROTECTOR
1025-
paca_ptrs[cpu]->canary = idle->stack_canary;
1026-
#endif
10271021
#endif
10281022
ti->cpu = cpu;
10291023
secondary_ti = current_set[cpu] = ti;
@@ -1316,6 +1310,8 @@ void start_secondary(void *unused)
13161310
notify_cpu_starting(cpu);
13171311
set_cpu_online(cpu, true);
13181312

1313+
boot_init_stack_canary();
1314+
13191315
local_irq_enable();
13201316

13211317
/* We can enable ftrace for secondary cpus now */

0 commit comments

Comments
 (0)