Skip to content

Commit 88485be

Browse files
committed
scs: Move scs_overflow_check() out of architecture code
There is nothing architecture-specific about scs_overflow_check() as it's just a trivial wrapper around scs_corrupted(). For parity with task_stack_end_corrupted(), rename scs_corrupted() to task_scs_end_corrupted() and call it from schedule_debug() when CONFIG_SCHED_STACK_END_CHECK_is enabled, which better reflects its purpose as a debug feature to catch inadvertent overflow of the SCS. Finally, remove the unused scs_overflow_check() function entirely. This has absolutely no impact on architectures that do not support SCS (currently arm64 only). Tested-by: Sami Tolvanen <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 711e8b0 commit 88485be

File tree

6 files changed

+8
-24
lines changed

6 files changed

+8
-24
lines changed

arch/arm64/include/asm/scs.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@
2424
.endm
2525
#endif /* CONFIG_SHADOW_CALL_STACK */
2626

27-
#else /* __ASSEMBLY__ */
28-
29-
#include <linux/scs.h>
30-
31-
#ifdef CONFIG_SHADOW_CALL_STACK
32-
33-
static inline void scs_overflow_check(struct task_struct *tsk)
34-
{
35-
if (unlikely(scs_corrupted(tsk)))
36-
panic("corrupted shadow stack detected inside scheduler\n");
37-
}
38-
39-
#else /* CONFIG_SHADOW_CALL_STACK */
40-
41-
static inline void scs_overflow_check(struct task_struct *tsk) {}
42-
43-
#endif /* CONFIG_SHADOW_CALL_STACK */
44-
4527
#endif /* __ASSEMBLY __ */
4628

4729
#endif /* _ASM_SCS_H */

arch/arm64/kernel/process.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include <asm/mmu_context.h>
5353
#include <asm/processor.h>
5454
#include <asm/pointer_auth.h>
55-
#include <asm/scs.h>
5655
#include <asm/stacktrace.h>
5756

5857
#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK)
@@ -516,7 +515,6 @@ __notrace_funcgraph struct task_struct *__switch_to(struct task_struct *prev,
516515
entry_task_switch(next);
517516
uao_thread_switch(next);
518517
ssbs_thread_switch(next);
519-
scs_overflow_check(next);
520518

521519
/*
522520
* Complete any pending TLB or cache maintenance on this CPU in case

arch/arm64/kernel/scs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
#include <linux/percpu.h>
9-
#include <asm/scs.h>
9+
#include <linux/scs.h>
1010

1111
/* Allocate a static per-CPU shadow stack */
1212
#define DEFINE_SCS(name) \

include/linux/scs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static inline unsigned long *__scs_magic(void *s)
4747
return (unsigned long *)(s + SCS_SIZE) - 1;
4848
}
4949

50-
static inline bool scs_corrupted(struct task_struct *tsk)
50+
static inline bool task_scs_end_corrupted(struct task_struct *tsk)
5151
{
5252
unsigned long *magic = __scs_magic(task_scs(tsk));
5353
unsigned long sz = task_scs_sp(tsk) - task_scs(tsk);
@@ -60,8 +60,8 @@ static inline bool scs_corrupted(struct task_struct *tsk)
6060
static inline void scs_init(void) {}
6161
static inline void scs_task_reset(struct task_struct *tsk) {}
6262
static inline int scs_prepare(struct task_struct *tsk, int node) { return 0; }
63-
static inline bool scs_corrupted(struct task_struct *tsk) { return false; }
6463
static inline void scs_release(struct task_struct *tsk) {}
64+
static inline bool task_scs_end_corrupted(struct task_struct *tsk) { return false; }
6565

6666
#endif /* CONFIG_SHADOW_CALL_STACK */
6767

kernel/sched/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,6 +3878,9 @@ static inline void schedule_debug(struct task_struct *prev, bool preempt)
38783878
#ifdef CONFIG_SCHED_STACK_END_CHECK
38793879
if (task_stack_end_corrupted(prev))
38803880
panic("corrupted stack end detected inside scheduler\n");
3881+
3882+
if (task_scs_end_corrupted(prev))
3883+
panic("corrupted shadow stack detected inside scheduler\n");
38813884
#endif
38823885

38833886
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP

kernel/scs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void scs_release(struct task_struct *tsk)
9898
if (!s)
9999
return;
100100

101-
WARN(scs_corrupted(tsk), "corrupted shadow stack detected when freeing task\n");
101+
WARN(task_scs_end_corrupted(tsk),
102+
"corrupted shadow stack detected when freeing task\n");
102103
scs_check_usage(tsk);
103104
scs_free(s);
104105
}

0 commit comments

Comments
 (0)