Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3953e15 authored by Sami Tolvanen's avatar Sami Tolvanen Committed by Alistair Delva
Browse files

FROMLIST: arm64: preserve x18 when CPU is suspended

Don't lose the current task's shadow stack when the CPU is suspended.

Bug: 145210207
Change-Id: I8f74f33b4b2c707e25e46bea4fb8a8f5ea1a7036
(am from https://lore.kernel.org/patchwork/patch/1149059/

)
Reviewed-by: default avatarNick Desaulniers <ndesaulniers@google.com>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarMark Rutland <mark.rutland@arm.com>
Signed-off-by: default avatarSami Tolvanen <samitolvanen@google.com>
parent 186d6788
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#ifndef __ASM_SUSPEND_H
#define __ASM_SUSPEND_H

#define NR_CTX_REGS 12
#define NR_CTX_REGS 13
#define NR_CALLEE_SAVED_REGS 12

/*
+14 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ ENDPROC(cpu_do_idle)
 * cpu_do_suspend - save CPU registers context
 *
 * x0: virtual address of context pointer
 *
 * This must be kept in sync with struct cpu_suspend_ctx in <asm/suspend.h>.
 */
ENTRY(cpu_do_suspend)
	mrs	x2, tpidr_el0
@@ -95,6 +97,11 @@ alternative_endif
	stp	x8, x9, [x0, #48]
	stp	x10, x11, [x0, #64]
	stp	x12, x13, [x0, #80]
	/*
	 * Save x18 as it may be used as a platform register, e.g. by shadow
	 * call stack.
	 */
	str	x18, [x0, #96]
	ret
ENDPROC(cpu_do_suspend)

@@ -111,6 +118,13 @@ ENTRY(cpu_do_resume)
	ldp	x9, x10, [x0, #48]
	ldp	x11, x12, [x0, #64]
	ldp	x13, x14, [x0, #80]
	/*
	 * Restore x18, as it may be used as a platform register, and clear
	 * the buffer to minimize the risk of exposure when used for shadow
	 * call stack.
	 */
	ldr	x18, [x0, #96]
	str	xzr, [x0, #96]
	msr	tpidr_el0, x2
	msr	tpidrro_el0, x3
	msr	contextidr_el1, x4