xref: /linux-6.15/include/linux/stackleak.h (revision 964c9dff)
1afaef01cSAlexander Popov /* SPDX-License-Identifier: GPL-2.0 */
2afaef01cSAlexander Popov #ifndef _LINUX_STACKLEAK_H
3afaef01cSAlexander Popov #define _LINUX_STACKLEAK_H
4afaef01cSAlexander Popov 
5afaef01cSAlexander Popov #include <linux/sched.h>
6afaef01cSAlexander Popov #include <linux/sched/task_stack.h>
7afaef01cSAlexander Popov 
8afaef01cSAlexander Popov /*
9afaef01cSAlexander Popov  * Check that the poison value points to the unused hole in the
10afaef01cSAlexander Popov  * virtual memory map for your platform.
11afaef01cSAlexander Popov  */
12afaef01cSAlexander Popov #define STACKLEAK_POISON -0xBEEF
13afaef01cSAlexander Popov #define STACKLEAK_SEARCH_DEPTH 128
14afaef01cSAlexander Popov 
15afaef01cSAlexander Popov #ifdef CONFIG_GCC_PLUGIN_STACKLEAK
16afaef01cSAlexander Popov #include <asm/stacktrace.h>
17afaef01cSAlexander Popov 
18afaef01cSAlexander Popov static inline void stackleak_task_init(struct task_struct *t)
19afaef01cSAlexander Popov {
20afaef01cSAlexander Popov 	t->lowest_stack = (unsigned long)end_of_stack(t) + sizeof(unsigned long);
21c8d12627SAlexander Popov # ifdef CONFIG_STACKLEAK_METRICS
22c8d12627SAlexander Popov 	t->prev_lowest_stack = t->lowest_stack;
23c8d12627SAlexander Popov # endif
24afaef01cSAlexander Popov }
25*964c9dffSAlexander Popov 
26*964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
27*964c9dffSAlexander Popov int stack_erasing_sysctl(struct ctl_table *table, int write,
28*964c9dffSAlexander Popov 			void __user *buffer, size_t *lenp, loff_t *ppos);
29*964c9dffSAlexander Popov #endif
30*964c9dffSAlexander Popov 
31afaef01cSAlexander Popov #else /* !CONFIG_GCC_PLUGIN_STACKLEAK */
32afaef01cSAlexander Popov static inline void stackleak_task_init(struct task_struct *t) { }
33afaef01cSAlexander Popov #endif
34afaef01cSAlexander Popov 
35afaef01cSAlexander Popov #endif
36