xref: /openbmc/linux/drivers/misc/lkdtm/lkdtm.h (revision 94d964e5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LKDTM_H
3 #define __LKDTM_H
4 
5 #define pr_fmt(fmt) "lkdtm: " fmt
6 
7 #include <linux/kernel.h>
8 
9 extern char *lkdtm_kernel_info;
10 
11 #define pr_expected_config(kconfig)				\
12 {								\
13 	if (IS_ENABLED(kconfig)) 				\
14 		pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \
15 			lkdtm_kernel_info);			\
16 	else							\
17 		pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \
18 			lkdtm_kernel_info);			\
19 }
20 
21 #ifndef MODULE
22 int lkdtm_check_bool_cmdline(const char *param);
23 #define pr_expected_config_param(kconfig, param)		\
24 {								\
25 	if (IS_ENABLED(kconfig)) {				\
26 		switch (lkdtm_check_bool_cmdline(param)) {	\
27 		case 0:						\
28 			pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \
29 				lkdtm_kernel_info);		\
30 			break;					\
31 		case 1:						\
32 			pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \
33 				lkdtm_kernel_info);		\
34 			break;					\
35 		default:					\
36 			pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \
37 				lkdtm_kernel_info);		\
38 		}						\
39 	} else {						\
40 		switch (lkdtm_check_bool_cmdline(param)) {	\
41 		case 0:						\
42 			pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \
43 				lkdtm_kernel_info);		\
44 			break;					\
45 		case 1:						\
46 			pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \
47 				lkdtm_kernel_info);		\
48 			break;					\
49 		default:					\
50 			pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \
51 				lkdtm_kernel_info);		\
52 			break;					\
53 		}						\
54 	}							\
55 }
56 #else
57 #define pr_expected_config_param(kconfig, param) pr_expected_config(kconfig)
58 #endif
59 
60 /* bugs.c */
61 void __init lkdtm_bugs_init(int *recur_param);
62 void lkdtm_PANIC(void);
63 void lkdtm_BUG(void);
64 void lkdtm_WARNING(void);
65 void lkdtm_WARNING_MESSAGE(void);
66 void lkdtm_EXCEPTION(void);
67 void lkdtm_LOOP(void);
68 void lkdtm_EXHAUST_STACK(void);
69 void lkdtm_CORRUPT_STACK(void);
70 void lkdtm_CORRUPT_STACK_STRONG(void);
71 void lkdtm_REPORT_STACK(void);
72 void lkdtm_REPORT_STACK_CANARY(void);
73 void lkdtm_UNALIGNED_LOAD_STORE_WRITE(void);
74 void lkdtm_SOFTLOCKUP(void);
75 void lkdtm_HARDLOCKUP(void);
76 void lkdtm_SPINLOCKUP(void);
77 void lkdtm_HUNG_TASK(void);
78 void lkdtm_OVERFLOW_SIGNED(void);
79 void lkdtm_OVERFLOW_UNSIGNED(void);
80 void lkdtm_ARRAY_BOUNDS(void);
81 void lkdtm_CORRUPT_LIST_ADD(void);
82 void lkdtm_CORRUPT_LIST_DEL(void);
83 void lkdtm_STACK_GUARD_PAGE_LEADING(void);
84 void lkdtm_STACK_GUARD_PAGE_TRAILING(void);
85 void lkdtm_UNSET_SMEP(void);
86 void lkdtm_DOUBLE_FAULT(void);
87 void lkdtm_CORRUPT_PAC(void);
88 
89 /* heap.c */
90 void __init lkdtm_heap_init(void);
91 void __exit lkdtm_heap_exit(void);
92 void lkdtm_VMALLOC_LINEAR_OVERFLOW(void);
93 void lkdtm_SLAB_LINEAR_OVERFLOW(void);
94 void lkdtm_WRITE_AFTER_FREE(void);
95 void lkdtm_READ_AFTER_FREE(void);
96 void lkdtm_WRITE_BUDDY_AFTER_FREE(void);
97 void lkdtm_READ_BUDDY_AFTER_FREE(void);
98 void lkdtm_SLAB_INIT_ON_ALLOC(void);
99 void lkdtm_BUDDY_INIT_ON_ALLOC(void);
100 void lkdtm_SLAB_FREE_DOUBLE(void);
101 void lkdtm_SLAB_FREE_CROSS(void);
102 void lkdtm_SLAB_FREE_PAGE(void);
103 
104 /* perms.c */
105 void __init lkdtm_perms_init(void);
106 void lkdtm_WRITE_RO(void);
107 void lkdtm_WRITE_RO_AFTER_INIT(void);
108 void lkdtm_WRITE_KERN(void);
109 void lkdtm_EXEC_DATA(void);
110 void lkdtm_EXEC_STACK(void);
111 void lkdtm_EXEC_KMALLOC(void);
112 void lkdtm_EXEC_VMALLOC(void);
113 void lkdtm_EXEC_RODATA(void);
114 void lkdtm_EXEC_USERSPACE(void);
115 void lkdtm_EXEC_NULL(void);
116 void lkdtm_ACCESS_USERSPACE(void);
117 void lkdtm_ACCESS_NULL(void);
118 
119 /* refcount.c */
120 void lkdtm_REFCOUNT_INC_OVERFLOW(void);
121 void lkdtm_REFCOUNT_ADD_OVERFLOW(void);
122 void lkdtm_REFCOUNT_INC_NOT_ZERO_OVERFLOW(void);
123 void lkdtm_REFCOUNT_ADD_NOT_ZERO_OVERFLOW(void);
124 void lkdtm_REFCOUNT_DEC_ZERO(void);
125 void lkdtm_REFCOUNT_DEC_NEGATIVE(void);
126 void lkdtm_REFCOUNT_DEC_AND_TEST_NEGATIVE(void);
127 void lkdtm_REFCOUNT_SUB_AND_TEST_NEGATIVE(void);
128 void lkdtm_REFCOUNT_INC_ZERO(void);
129 void lkdtm_REFCOUNT_ADD_ZERO(void);
130 void lkdtm_REFCOUNT_INC_SATURATED(void);
131 void lkdtm_REFCOUNT_DEC_SATURATED(void);
132 void lkdtm_REFCOUNT_ADD_SATURATED(void);
133 void lkdtm_REFCOUNT_INC_NOT_ZERO_SATURATED(void);
134 void lkdtm_REFCOUNT_ADD_NOT_ZERO_SATURATED(void);
135 void lkdtm_REFCOUNT_DEC_AND_TEST_SATURATED(void);
136 void lkdtm_REFCOUNT_SUB_AND_TEST_SATURATED(void);
137 void lkdtm_REFCOUNT_TIMING(void);
138 void lkdtm_ATOMIC_TIMING(void);
139 
140 /* rodata.c */
141 void lkdtm_rodata_do_nothing(void);
142 
143 /* usercopy.c */
144 void __init lkdtm_usercopy_init(void);
145 void __exit lkdtm_usercopy_exit(void);
146 void lkdtm_USERCOPY_HEAP_SIZE_TO(void);
147 void lkdtm_USERCOPY_HEAP_SIZE_FROM(void);
148 void lkdtm_USERCOPY_HEAP_WHITELIST_TO(void);
149 void lkdtm_USERCOPY_HEAP_WHITELIST_FROM(void);
150 void lkdtm_USERCOPY_STACK_FRAME_TO(void);
151 void lkdtm_USERCOPY_STACK_FRAME_FROM(void);
152 void lkdtm_USERCOPY_STACK_BEYOND(void);
153 void lkdtm_USERCOPY_KERNEL(void);
154 
155 /* stackleak.c */
156 void lkdtm_STACKLEAK_ERASING(void);
157 
158 /* cfi.c */
159 void lkdtm_CFI_FORWARD_PROTO(void);
160 
161 /* fortify.c */
162 void lkdtm_FORTIFIED_OBJECT(void);
163 void lkdtm_FORTIFIED_SUBOBJECT(void);
164 void lkdtm_FORTIFIED_STRSCPY(void);
165 
166 /* powerpc.c */
167 void lkdtm_PPC_SLB_MULTIHIT(void);
168 
169 #endif
170