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