Skip to content

Commit 59b37fe

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: Stash shadow stack pointer in the task struct on interrupt
Instead of reloading the shadow call stack pointer from the ordinary stack, which may be vulnerable to the kind of gadget based attacks shadow call stacks were designed to prevent, let's store a task's shadow call stack pointer in the task struct when switching to the shadow IRQ stack. Given that currently, the task_struct::scs_sp field is only used to preserve the shadow call stack pointer while a task is scheduled out or running in user space, reusing this field to preserve and restore it while running off the IRQ stack must be safe, as those occurrences are guaranteed to never overlap. (The stack switching logic only switches stacks when running from the task stack, and so the value being saved here always corresponds to the task mode shadow stack) While at it, fold a mov/add/mov sequence into a single add. Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 2198d07 commit 59b37fe

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

arch/arm64/kernel/entry.S

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -876,19 +876,19 @@ NOKPROBE(ret_from_fork)
876876
*/
877877
SYM_FUNC_START(call_on_irq_stack)
878878
#ifdef CONFIG_SHADOW_CALL_STACK
879-
stp scs_sp, xzr, [sp, #-16]!
879+
get_current_task x16
880+
scs_save x16
880881
ldr_this_cpu scs_sp, irq_shadow_call_stack_ptr, x17
881882
#endif
883+
882884
/* Create a frame record to save our LR and SP (implicit in FP) */
883885
stp x29, x30, [sp, #-16]!
884886
mov x29, sp
885887

886888
ldr_this_cpu x16, irq_stack_ptr, x17
887-
mov x15, #IRQ_STACK_SIZE
888-
add x16, x16, x15
889889

890890
/* Move to the new stack and call the function there */
891-
mov sp, x16
891+
add sp, x16, #IRQ_STACK_SIZE
892892
blr x1
893893

894894
/*
@@ -897,9 +897,7 @@ SYM_FUNC_START(call_on_irq_stack)
897897
*/
898898
mov sp, x29
899899
ldp x29, x30, [sp], #16
900-
#ifdef CONFIG_SHADOW_CALL_STACK
901-
ldp scs_sp, xzr, [sp], #16
902-
#endif
900+
scs_load_current
903901
ret
904902
SYM_FUNC_END(call_on_irq_stack)
905903
NOKPROBE(call_on_irq_stack)

0 commit comments

Comments
 (0)