Skip to content

Commit cfe9d44

Browse files
vaibhav92stewartsmith
authored andcommitted
core/cpu: Prevent clobbering of stack guard for boot-cpu
Commit 90d5393 ("core/cpu: discover stack region size before initialising memory regions") introduced memzero for struct cpu_thread in init_cpu_thread(). This has an unintended side effect of clobbering the stack-guard cannery of the boot_cpu stack. This results in opal failing to init with this failure message: CPU: P9 generation processor (max 4 threads/core) CPU: Boot CPU PIR is 0x0004 PVR is 0x004e1200 Guard skip = 0 Stack corruption detected ! Aborting! CPU 0004 Backtrace: S: 0000000031c13ab0 R: 0000000030013b0c .backtrace+0x5c S: 0000000031c13b50 R: 000000003001bd18 ._abort+0x60 S: 0000000031c13be0 R: 0000000030013bbc .__stack_chk_fail+0x54 S: 0000000031c13c60 R: 00000000300c5b70 .memset+0x12c S: 0000000031c13d00 R: 0000000030019aa8 .init_cpu_thread+0x40 S: 0000000031c13d90 R: 000000003001b520 .init_boot_cpu+0x188 S: 0000000031c13e30 R: 0000000030015050 .main_cpu_entry+0xd0 S: 0000000031c13f00 R: 0000000030002700 boot_entry+0x1c0 So the patch provides a fix by tweaking the memset() call in init_cpu_thread() to skip over the stack-guard cannery. Fixes:90d53934c2da("core/cpu: discover stack region size before initialising memory regions") Signed-off-by: Vaibhav Jain <[email protected]> Reviewed-by: Nicholas Piggin <[email protected]> Signed-off-by: Stewart Smith <[email protected]>
1 parent 1b526d8 commit cfe9d44

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/cpu.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,11 @@ static void init_cpu_thread(struct cpu_thread *t,
826826
enum cpu_thread_state state,
827827
unsigned int pir)
828828
{
829-
memset(t, 0, sizeof(struct cpu_thread));
829+
/* offset within cpu_thread to prevent stack_guard clobber */
830+
const size_t guard_skip = container_off_var(t, stack_guard) +
831+
sizeof(t->stack_guard);
832+
833+
memset(t + guard_skip, 0, sizeof(struct cpu_thread) - guard_skip);
830834
init_lock(&t->dctl_lock);
831835
init_lock(&t->job_lock);
832836
list_head_init(&t->job_queue);

0 commit comments

Comments
 (0)