1039a1c42SKees Cook /* SPDX-License-Identifier: GPL-2.0 */ 2039a1c42SKees Cook #ifndef __LKDTM_H 3039a1c42SKees Cook #define __LKDTM_H 4039a1c42SKees Cook 5039a1c42SKees Cook #define pr_fmt(fmt) "lkdtm: " fmt 6039a1c42SKees Cook 7039a1c42SKees Cook #include <linux/kernel.h> 8b8661450SKees Cook 93a3a11e6SKees Cook extern char *lkdtm_kernel_info; 10039a1c42SKees Cook 115b777131SKees Cook #define pr_expected_config(kconfig) \ 128bfdbdddSChristophe Leroy do { \ 135b777131SKees Cook if (IS_ENABLED(kconfig)) \ 143a3a11e6SKees Cook pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \ 153a3a11e6SKees Cook lkdtm_kernel_info); \ 165b777131SKees Cook else \ 173a3a11e6SKees Cook pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \ 183a3a11e6SKees Cook lkdtm_kernel_info); \ 198bfdbdddSChristophe Leroy } while (0) 205b777131SKees Cook 215b777131SKees Cook #ifndef MODULE 225b777131SKees Cook int lkdtm_check_bool_cmdline(const char *param); 235b777131SKees Cook #define pr_expected_config_param(kconfig, param) \ 248bfdbdddSChristophe Leroy do { \ 255b777131SKees Cook if (IS_ENABLED(kconfig)) { \ 265b777131SKees Cook switch (lkdtm_check_bool_cmdline(param)) { \ 275b777131SKees Cook case 0: \ 283a3a11e6SKees Cook pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \ 293a3a11e6SKees Cook lkdtm_kernel_info); \ 305b777131SKees Cook break; \ 315b777131SKees Cook case 1: \ 323a3a11e6SKees Cook pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \ 333a3a11e6SKees Cook lkdtm_kernel_info); \ 345b777131SKees Cook break; \ 355b777131SKees Cook default: \ 363a3a11e6SKees Cook pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \ 373a3a11e6SKees Cook lkdtm_kernel_info); \ 385b777131SKees Cook } \ 395b777131SKees Cook } else { \ 405b777131SKees Cook switch (lkdtm_check_bool_cmdline(param)) { \ 415b777131SKees Cook case 0: \ 423a3a11e6SKees Cook pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \ 433a3a11e6SKees Cook lkdtm_kernel_info); \ 445b777131SKees Cook break; \ 455b777131SKees Cook case 1: \ 463a3a11e6SKees Cook pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \ 473a3a11e6SKees Cook lkdtm_kernel_info); \ 485b777131SKees Cook break; \ 495b777131SKees Cook default: \ 503a3a11e6SKees Cook pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \ 513a3a11e6SKees Cook lkdtm_kernel_info); \ 525b777131SKees Cook break; \ 535b777131SKees Cook } \ 545b777131SKees Cook } \ 558bfdbdddSChristophe Leroy } while (0) 565b777131SKees Cook #else 575b777131SKees Cook #define pr_expected_config_param(kconfig, param) pr_expected_config(kconfig) 585b777131SKees Cook #endif 595b777131SKees Cook 60*73f62e60SKees Cook /* Crash types. */ 61*73f62e60SKees Cook struct crashtype { 62*73f62e60SKees Cook const char *name; 63*73f62e60SKees Cook void (*func)(void); 64*73f62e60SKees Cook }; 65039a1c42SKees Cook 66*73f62e60SKees Cook #define CRASHTYPE(_name) \ 67*73f62e60SKees Cook { \ 68*73f62e60SKees Cook .name = __stringify(_name), \ 69*73f62e60SKees Cook .func = lkdtm_ ## _name, \ 70*73f62e60SKees Cook } 71*73f62e60SKees Cook 72*73f62e60SKees Cook /* Category's collection of crashtypes. */ 73*73f62e60SKees Cook struct crashtype_category { 74*73f62e60SKees Cook struct crashtype *crashtypes; 75*73f62e60SKees Cook size_t len; 76*73f62e60SKees Cook }; 77*73f62e60SKees Cook 78*73f62e60SKees Cook /* Each category's crashtypes list. */ 79*73f62e60SKees Cook extern struct crashtype_category bugs_crashtypes; 80*73f62e60SKees Cook extern struct crashtype_category heap_crashtypes; 81*73f62e60SKees Cook extern struct crashtype_category perms_crashtypes; 82*73f62e60SKees Cook extern struct crashtype_category refcount_crashtypes; 83*73f62e60SKees Cook extern struct crashtype_category usercopy_crashtypes; 84*73f62e60SKees Cook extern struct crashtype_category stackleak_crashtypes; 85*73f62e60SKees Cook extern struct crashtype_category cfi_crashtypes; 86*73f62e60SKees Cook extern struct crashtype_category fortify_crashtypes; 87*73f62e60SKees Cook extern struct crashtype_category powerpc_crashtypes; 88*73f62e60SKees Cook 89*73f62e60SKees Cook /* Each category's init/exit routines. */ 90*73f62e60SKees Cook void __init lkdtm_bugs_init(int *recur_param); 91966fede8SKees Cook void __init lkdtm_heap_init(void); 92966fede8SKees Cook void __exit lkdtm_heap_exit(void); 93039a1c42SKees Cook void __init lkdtm_perms_init(void); 94039a1c42SKees Cook void __init lkdtm_usercopy_init(void); 95039a1c42SKees Cook void __exit lkdtm_usercopy_exit(void); 96039a1c42SKees Cook 97*73f62e60SKees Cook /* Special declaration for function-in-rodata. */ 98*73f62e60SKees Cook void lkdtm_rodata_do_nothing(void); 993ba150fbSGanesh Goudar 100039a1c42SKees Cook #endif 101