1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_STACKLEAK_H 3 #define _LINUX_STACKLEAK_H 4 5 #include <linux/sched.h> 6 #include <linux/sched/task_stack.h> 7 8 /* 9 * Check that the poison value points to the unused hole in the 10 * virtual memory map for your platform. 11 */ 12 #define STACKLEAK_POISON -0xBEEF 13 #define STACKLEAK_SEARCH_DEPTH 128 14 15 #ifdef CONFIG_GCC_PLUGIN_STACKLEAK 16 #include <asm/stacktrace.h> 17 18 /* 19 * The lowest address on tsk's stack which we can plausibly erase. 20 */ 21 static __always_inline unsigned long 22 stackleak_task_low_bound(const struct task_struct *tsk) 23 { 24 /* 25 * The lowest unsigned long on the task stack contains STACK_END_MAGIC, 26 * which we must not corrupt. 27 */ 28 return (unsigned long)end_of_stack(tsk) + sizeof(unsigned long); 29 } 30 31 static inline void stackleak_task_init(struct task_struct *t) 32 { 33 t->lowest_stack = stackleak_task_low_bound(t); 34 # ifdef CONFIG_STACKLEAK_METRICS 35 t->prev_lowest_stack = t->lowest_stack; 36 # endif 37 } 38 39 #else /* !CONFIG_GCC_PLUGIN_STACKLEAK */ 40 static inline void stackleak_task_init(struct task_struct *t) { } 41 #endif 42 43 #endif 44