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_UNALIGNED_LOAD_STORE_WRITE(void); 73 void lkdtm_SOFTLOCKUP(void); 74 void lkdtm_HARDLOCKUP(void); 75 void lkdtm_SPINLOCKUP(void); 76 void lkdtm_HUNG_TASK(void); 77 void lkdtm_OVERFLOW_SIGNED(void); 78 void lkdtm_OVERFLOW_UNSIGNED(void); 79 void lkdtm_ARRAY_BOUNDS(void); 80 void lkdtm_CORRUPT_LIST_ADD(void); 81 void lkdtm_CORRUPT_LIST_DEL(void); 82 void lkdtm_STACK_GUARD_PAGE_LEADING(void); 83 void lkdtm_STACK_GUARD_PAGE_TRAILING(void); 84 void lkdtm_UNSET_SMEP(void); 85 void lkdtm_DOUBLE_FAULT(void); 86 void lkdtm_CORRUPT_PAC(void); 87 88 /* heap.c */ 89 void __init lkdtm_heap_init(void); 90 void __exit lkdtm_heap_exit(void); 91 void lkdtm_VMALLOC_LINEAR_OVERFLOW(void); 92 void lkdtm_SLAB_LINEAR_OVERFLOW(void); 93 void lkdtm_WRITE_AFTER_FREE(void); 94 void lkdtm_READ_AFTER_FREE(void); 95 void lkdtm_WRITE_BUDDY_AFTER_FREE(void); 96 void lkdtm_READ_BUDDY_AFTER_FREE(void); 97 void lkdtm_SLAB_INIT_ON_ALLOC(void); 98 void lkdtm_BUDDY_INIT_ON_ALLOC(void); 99 void lkdtm_SLAB_FREE_DOUBLE(void); 100 void lkdtm_SLAB_FREE_CROSS(void); 101 void lkdtm_SLAB_FREE_PAGE(void); 102 103 /* perms.c */ 104 void __init lkdtm_perms_init(void); 105 void lkdtm_WRITE_RO(void); 106 void lkdtm_WRITE_RO_AFTER_INIT(void); 107 void lkdtm_WRITE_KERN(void); 108 void lkdtm_EXEC_DATA(void); 109 void lkdtm_EXEC_STACK(void); 110 void lkdtm_EXEC_KMALLOC(void); 111 void lkdtm_EXEC_VMALLOC(void); 112 void lkdtm_EXEC_RODATA(void); 113 void lkdtm_EXEC_USERSPACE(void); 114 void lkdtm_EXEC_NULL(void); 115 void lkdtm_ACCESS_USERSPACE(void); 116 void lkdtm_ACCESS_NULL(void); 117 118 /* refcount.c */ 119 void lkdtm_REFCOUNT_INC_OVERFLOW(void); 120 void lkdtm_REFCOUNT_ADD_OVERFLOW(void); 121 void lkdtm_REFCOUNT_INC_NOT_ZERO_OVERFLOW(void); 122 void lkdtm_REFCOUNT_ADD_NOT_ZERO_OVERFLOW(void); 123 void lkdtm_REFCOUNT_DEC_ZERO(void); 124 void lkdtm_REFCOUNT_DEC_NEGATIVE(void); 125 void lkdtm_REFCOUNT_DEC_AND_TEST_NEGATIVE(void); 126 void lkdtm_REFCOUNT_SUB_AND_TEST_NEGATIVE(void); 127 void lkdtm_REFCOUNT_INC_ZERO(void); 128 void lkdtm_REFCOUNT_ADD_ZERO(void); 129 void lkdtm_REFCOUNT_INC_SATURATED(void); 130 void lkdtm_REFCOUNT_DEC_SATURATED(void); 131 void lkdtm_REFCOUNT_ADD_SATURATED(void); 132 void lkdtm_REFCOUNT_INC_NOT_ZERO_SATURATED(void); 133 void lkdtm_REFCOUNT_ADD_NOT_ZERO_SATURATED(void); 134 void lkdtm_REFCOUNT_DEC_AND_TEST_SATURATED(void); 135 void lkdtm_REFCOUNT_SUB_AND_TEST_SATURATED(void); 136 void lkdtm_REFCOUNT_TIMING(void); 137 void lkdtm_ATOMIC_TIMING(void); 138 139 /* rodata.c */ 140 void lkdtm_rodata_do_nothing(void); 141 142 /* usercopy.c */ 143 void __init lkdtm_usercopy_init(void); 144 void __exit lkdtm_usercopy_exit(void); 145 void lkdtm_USERCOPY_HEAP_SIZE_TO(void); 146 void lkdtm_USERCOPY_HEAP_SIZE_FROM(void); 147 void lkdtm_USERCOPY_HEAP_WHITELIST_TO(void); 148 void lkdtm_USERCOPY_HEAP_WHITELIST_FROM(void); 149 void lkdtm_USERCOPY_STACK_FRAME_TO(void); 150 void lkdtm_USERCOPY_STACK_FRAME_FROM(void); 151 void lkdtm_USERCOPY_STACK_BEYOND(void); 152 void lkdtm_USERCOPY_KERNEL(void); 153 154 /* stackleak.c */ 155 void lkdtm_STACKLEAK_ERASING(void); 156 157 /* cfi.c */ 158 void lkdtm_CFI_FORWARD_PROTO(void); 159 160 /* fortify.c */ 161 void lkdtm_FORTIFIED_OBJECT(void); 162 void lkdtm_FORTIFIED_SUBOBJECT(void); 163 void lkdtm_FORTIFIED_STRSCPY(void); 164 165 /* powerpc.c */ 166 void lkdtm_PPC_SLB_MULTIHIT(void); 167 168 #endif 169