Skip to content

Commit 439dc2a

Browse files
samitolvanenwilldeacon
authored andcommitted
arm64: scs: Add shadow stacks for SDEI
This change adds per-CPU shadow call stacks for the SDEI handler. Similarly to how the kernel stacks are handled, we add separate shadow stacks for normal and critical events. Signed-off-by: Sami Tolvanen <[email protected]> Reviewed-by: James Morse <[email protected]> Tested-by: James Morse <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 5287569 commit 439dc2a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

arch/arm64/kernel/entry.S

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,16 @@ SYM_CODE_START(__sdei_asm_handler)
10491049

10501050
mov x19, x1
10511051

1052+
#if defined(CONFIG_VMAP_STACK) || defined(CONFIG_SHADOW_CALL_STACK)
1053+
ldrb w4, [x19, #SDEI_EVENT_PRIORITY]
1054+
#endif
1055+
10521056
#ifdef CONFIG_VMAP_STACK
10531057
/*
10541058
* entry.S may have been using sp as a scratch register, find whether
10551059
* this is a normal or critical event and switch to the appropriate
10561060
* stack for this CPU.
10571061
*/
1058-
ldrb w4, [x19, #SDEI_EVENT_PRIORITY]
10591062
cbnz w4, 1f
10601063
ldr_this_cpu dst=x5, sym=sdei_stack_normal_ptr, tmp=x6
10611064
b 2f
@@ -1065,6 +1068,15 @@ SYM_CODE_START(__sdei_asm_handler)
10651068
mov sp, x5
10661069
#endif
10671070

1071+
#ifdef CONFIG_SHADOW_CALL_STACK
1072+
/* Use a separate shadow call stack for normal and critical events */
1073+
cbnz w4, 3f
1074+
adr_this_cpu dst=x18, sym=sdei_shadow_call_stack_normal, tmp=x6
1075+
b 4f
1076+
3: adr_this_cpu dst=x18, sym=sdei_shadow_call_stack_critical, tmp=x6
1077+
4:
1078+
#endif
1079+
10681080
/*
10691081
* We may have interrupted userspace, or a guest, or exit-from or
10701082
* return-to either of these. We can't trust sp_el0, restore it.

arch/arm64/kernel/scs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@
1313
DEFINE_PER_CPU(unsigned long [SCS_SIZE/sizeof(long)], name) \
1414

1515
DEFINE_SCS(irq_shadow_call_stack);
16+
17+
#ifdef CONFIG_ARM_SDE_INTERFACE
18+
DEFINE_SCS(sdei_shadow_call_stack_normal);
19+
DEFINE_SCS(sdei_shadow_call_stack_critical);
20+
#endif

0 commit comments

Comments
 (0)