Skip to content

Commit 6d37d81

Browse files
samitolvanenwilldeacon
authored andcommitted
arm64: Preserve register x18 when CPU is suspended
Don't lose the current task's shadow stack when the CPU is suspended. Signed-off-by: Sami Tolvanen <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent da64e9d commit 6d37d81

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

arch/arm64/include/asm/suspend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __ASM_SUSPEND_H
33
#define __ASM_SUSPEND_H
44

5-
#define NR_CTX_REGS 12
5+
#define NR_CTX_REGS 13
66
#define NR_CALLEE_SAVED_REGS 12
77

88
/*

arch/arm64/mm/proc.S

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
* cpu_do_suspend - save CPU registers context
5959
*
6060
* x0: virtual address of context pointer
61+
*
62+
* This must be kept in sync with struct cpu_suspend_ctx in <asm/suspend.h>.
6163
*/
6264
SYM_FUNC_START(cpu_do_suspend)
6365
mrs x2, tpidr_el0
@@ -82,6 +84,11 @@ alternative_endif
8284
stp x8, x9, [x0, #48]
8385
stp x10, x11, [x0, #64]
8486
stp x12, x13, [x0, #80]
87+
/*
88+
* Save x18 as it may be used as a platform register, e.g. by shadow
89+
* call stack.
90+
*/
91+
str x18, [x0, #96]
8592
ret
8693
SYM_FUNC_END(cpu_do_suspend)
8794

@@ -98,6 +105,13 @@ SYM_FUNC_START(cpu_do_resume)
98105
ldp x9, x10, [x0, #48]
99106
ldp x11, x12, [x0, #64]
100107
ldp x13, x14, [x0, #80]
108+
/*
109+
* Restore x18, as it may be used as a platform register, and clear
110+
* the buffer to minimize the risk of exposure when used for shadow
111+
* call stack.
112+
*/
113+
ldr x18, [x0, #96]
114+
str xzr, [x0, #96]
101115
msr tpidr_el0, x2
102116
msr tpidrro_el0, x3
103117
msr contextidr_el1, x4

0 commit comments

Comments
 (0)