Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9a49a528 KC |
2 | #ifndef __LKDTM_H |
3 | #define __LKDTM_H | |
4 | ||
6d2e91a6 KC |
5 | #define pr_fmt(fmt) "lkdtm: " fmt |
6 | ||
7 | #include <linux/kernel.h> | |
b8661450 | 8 | |
3a3a11e6 | 9 | extern char *lkdtm_kernel_info; |
6d2e91a6 | 10 | |
5b777131 | 11 | #define pr_expected_config(kconfig) \ |
8bfdbddd | 12 | do { \ |
5b777131 | 13 | if (IS_ENABLED(kconfig)) \ |
3a3a11e6 KC |
14 | pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \ |
15 | lkdtm_kernel_info); \ | |
5b777131 | 16 | else \ |
3a3a11e6 KC |
17 | pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \ |
18 | lkdtm_kernel_info); \ | |
8bfdbddd | 19 | } while (0) |
5b777131 KC |
20 | |
21 | #ifndef MODULE | |
22 | int lkdtm_check_bool_cmdline(const char *param); | |
23 | #define pr_expected_config_param(kconfig, param) \ | |
8bfdbddd | 24 | do { \ |
5b777131 KC |
25 | if (IS_ENABLED(kconfig)) { \ |
26 | switch (lkdtm_check_bool_cmdline(param)) { \ | |
27 | case 0: \ | |
3a3a11e6 KC |
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); \ | |
5b777131 KC |
30 | break; \ |
31 | case 1: \ | |
3a3a11e6 KC |
32 | pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \ |
33 | lkdtm_kernel_info); \ | |
5b777131 KC |
34 | break; \ |
35 | default: \ | |
3a3a11e6 KC |
36 | pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \ |
37 | lkdtm_kernel_info); \ | |
5b777131 KC |
38 | } \ |
39 | } else { \ | |
40 | switch (lkdtm_check_bool_cmdline(param)) { \ | |
41 | case 0: \ | |
3a3a11e6 KC |
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); \ | |
5b777131 KC |
44 | break; \ |
45 | case 1: \ | |
3a3a11e6 KC |
46 | pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \ |
47 | lkdtm_kernel_info); \ | |
5b777131 KC |
48 | break; \ |
49 | default: \ | |
3a3a11e6 KC |
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); \ | |
5b777131 KC |
52 | break; \ |
53 | } \ | |
54 | } \ | |
8bfdbddd | 55 | } while (0) |
5b777131 KC |
56 | #else |
57 | #define pr_expected_config_param(kconfig, param) pr_expected_config(kconfig) | |
58 | #endif | |
59 | ||
73f62e60 KC |
60 | /* Crash types. */ |
61 | struct crashtype { | |
62 | const char *name; | |
63 | void (*func)(void); | |
64 | }; | |
65 | ||
66 | #define CRASHTYPE(_name) \ | |
67 | { \ | |
68 | .name = __stringify(_name), \ | |
69 | .func = lkdtm_ ## _name, \ | |
70 | } | |
71 | ||
72 | /* Category's collection of crashtypes. */ | |
73 | struct crashtype_category { | |
74 | struct crashtype *crashtypes; | |
75 | size_t len; | |
76 | }; | |
77 | ||
78 | /* Each category's crashtypes list. */ | |
79 | extern struct crashtype_category bugs_crashtypes; | |
80 | extern struct crashtype_category heap_crashtypes; | |
81 | extern struct crashtype_category perms_crashtypes; | |
82 | extern struct crashtype_category refcount_crashtypes; | |
83 | extern struct crashtype_category usercopy_crashtypes; | |
84 | extern struct crashtype_category stackleak_crashtypes; | |
85 | extern struct crashtype_category cfi_crashtypes; | |
86 | extern struct crashtype_category fortify_crashtypes; | |
87 | extern struct crashtype_category powerpc_crashtypes; | |
88 | ||
89 | /* Each category's init/exit routines. */ | |
00f496c4 | 90 | void __init lkdtm_bugs_init(int *recur_param); |
966fede8 KC |
91 | void __init lkdtm_heap_init(void); |
92 | void __exit lkdtm_heap_exit(void); | |
0d9eb29b | 93 | void __init lkdtm_perms_init(void); |
a3dff71c KC |
94 | void __init lkdtm_usercopy_init(void); |
95 | void __exit lkdtm_usercopy_exit(void); | |
b0eb93cf | 96 | |
73f62e60 KC |
97 | /* Special declaration for function-in-rodata. */ |
98 | void lkdtm_rodata_do_nothing(void); | |
3ba150fb | 99 | |
9a49a528 | 100 | #endif |