summaryrefslogtreecommitdiff
path: root/arch/arm64/include/asm/scs.h
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2020-04-27 19:00:16 +0300
committerWill Deacon <will@kernel.org>2020-05-15 18:35:50 +0300
commit5287569a790d2546a06db07e391bf84b8bd6cf51 (patch)
tree137dc42c9e15afc1b7880798d2ea1ed146301211 /arch/arm64/include/asm/scs.h
parent9654736891c3ac6a60b52ce70d33cf57cf95bff7 (diff)
downloadlinux-5287569a790d2546a06db07e391bf84b8bd6cf51.tar.xz
arm64: Implement Shadow Call Stack
This change implements shadow stack switching, initial SCS set-up, and interrupt shadow stacks for arm64. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Will Deacon <will@kernel.org>
Diffstat (limited to 'arch/arm64/include/asm/scs.h')
-rw-r--r--arch/arm64/include/asm/scs.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/scs.h b/arch/arm64/include/asm/scs.h
new file mode 100644
index 000000000000..96549353b0cb
--- /dev/null
+++ b/arch/arm64/include/asm/scs.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_SCS_H
+#define _ASM_SCS_H
+
+#ifdef __ASSEMBLY__
+
+#ifdef CONFIG_SHADOW_CALL_STACK
+ .macro scs_load tsk, tmp
+ ldp x18, \tmp, [\tsk, #TSK_TI_SCS_BASE]
+ add x18, x18, \tmp
+ .endm
+
+ .macro scs_save tsk, tmp
+ ldr \tmp, [\tsk, #TSK_TI_SCS_BASE]
+ sub \tmp, x18, \tmp
+ str \tmp, [\tsk, #TSK_TI_SCS_OFFSET]
+ .endm
+#else
+ .macro scs_load tsk, tmp
+ .endm
+
+ .macro scs_save tsk, tmp
+ .endm
+#endif /* CONFIG_SHADOW_CALL_STACK */
+
+#else /* __ASSEMBLY__ */
+
+#include <linux/scs.h>
+
+#ifdef CONFIG_SHADOW_CALL_STACK
+
+static inline void scs_overflow_check(struct task_struct *tsk)
+{
+ if (unlikely(scs_corrupted(tsk)))
+ panic("corrupted shadow stack detected inside scheduler\n");
+}
+
+#else /* CONFIG_SHADOW_CALL_STACK */
+
+static inline void scs_overflow_check(struct task_struct *tsk) {}
+
+#endif /* CONFIG_SHADOW_CALL_STACK */
+
+#endif /* __ASSEMBLY __ */
+
+#endif /* _ASM_SCS_H */