1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Shadow Call Stack support. 4 * 5 * Copyright (C) 2019 Google LLC 6 */ 7 8 #ifndef _LINUX_SCS_H 9 #define _LINUX_SCS_H 10 11 #include <linux/gfp.h> 12 #include <linux/sched.h> 13 #include <asm/page.h> 14 15 #ifdef CONFIG_SHADOW_CALL_STACK 16 17 #ifdef CONFIG_SHADOW_CALL_STACK_VMAP 18 #define SCS_SIZE PAGE_SIZE 19 #else 20 /* 21 * In testing, 1 KiB shadow stack size (i.e. 128 stack frames on a 64-bit 22 * architecture) provided ~40% safety margin on stack usage while keeping 23 * memory allocation overhead reasonable. 24 */ 25 #define SCS_SIZE 1024UL 26 #endif 27 28 #define GFP_SCS (GFP_KERNEL | __GFP_ZERO) 29 30 /* 31 * A random number outside the kernel's virtual address space to mark the 32 * end of the shadow stack. 33 */ 34 #define SCS_END_MAGIC 0xaf0194819b1635f6UL 35 36 #define task_scs(tsk) (task_thread_info(tsk)->shadow_call_stack) 37 task_set_scs(struct task_struct * tsk,void * s)38static inline void task_set_scs(struct task_struct *tsk, void *s) 39 { 40 task_scs(tsk) = s; 41 } 42 43 extern void scs_init(void); 44 extern void scs_task_reset(struct task_struct *tsk); 45 extern int scs_prepare(struct task_struct *tsk, int node); 46 extern bool scs_corrupted(struct task_struct *tsk); 47 extern void scs_release(struct task_struct *tsk); 48 49 #else /* CONFIG_SHADOW_CALL_STACK */ 50 51 #define task_scs(tsk) NULL 52 task_set_scs(struct task_struct * tsk,void * s)53static inline void task_set_scs(struct task_struct *tsk, void *s) {} scs_init(void)54static inline void scs_init(void) {} scs_task_reset(struct task_struct * tsk)55static inline void scs_task_reset(struct task_struct *tsk) {} scs_prepare(struct task_struct * tsk,int node)56static inline int scs_prepare(struct task_struct *tsk, int node) { return 0; } scs_corrupted(struct task_struct * tsk)57static inline bool scs_corrupted(struct task_struct *tsk) { return false; } scs_release(struct task_struct * tsk)58static inline void scs_release(struct task_struct *tsk) {} 59 60 #endif /* CONFIG_SHADOW_CALL_STACK */ 61 62 #endif /* _LINUX_SCS_H */ 63