Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LKDTM_H
0003 #define __LKDTM_H
0004 
0005 #define pr_fmt(fmt) "lkdtm: " fmt
0006 
0007 #include <linux/kernel.h>
0008 
0009 extern char *lkdtm_kernel_info;
0010 
0011 #define pr_expected_config(kconfig)             \
0012 do {                                \
0013     if (IS_ENABLED(kconfig))                \
0014         pr_err("Unexpected! This %s was built with " #kconfig "=y\n", \
0015             lkdtm_kernel_info);         \
0016     else                            \
0017         pr_warn("This is probably expected, since this %s was built *without* " #kconfig "=y\n", \
0018             lkdtm_kernel_info);         \
0019 } while (0)
0020 
0021 #ifndef MODULE
0022 int lkdtm_check_bool_cmdline(const char *param);
0023 #define pr_expected_config_param(kconfig, param)        \
0024 do {                                \
0025     if (IS_ENABLED(kconfig)) {              \
0026         switch (lkdtm_check_bool_cmdline(param)) {  \
0027         case 0:                     \
0028             pr_warn("This is probably expected, since this %s was built with " #kconfig "=y but booted with '" param "=N'\n", \
0029                 lkdtm_kernel_info);     \
0030             break;                  \
0031         case 1:                     \
0032             pr_err("Unexpected! This %s was built with " #kconfig "=y and booted with '" param "=Y'\n", \
0033                 lkdtm_kernel_info);     \
0034             break;                  \
0035         default:                    \
0036             pr_err("Unexpected! This %s was built with " #kconfig "=y (and booted without '" param "' specified)\n", \
0037                 lkdtm_kernel_info);     \
0038         }                       \
0039     } else {                        \
0040         switch (lkdtm_check_bool_cmdline(param)) {  \
0041         case 0:                     \
0042             pr_warn("This is probably expected, as this %s was built *without* " #kconfig "=y and booted with '" param "=N'\n", \
0043                 lkdtm_kernel_info);     \
0044             break;                  \
0045         case 1:                     \
0046             pr_err("Unexpected! This %s was built *without* " #kconfig "=y but booted with '" param "=Y'\n", \
0047                 lkdtm_kernel_info);     \
0048             break;                  \
0049         default:                    \
0050             pr_err("This is probably expected, since this %s was built *without* " #kconfig "=y (and booted without '" param "' specified)\n", \
0051                 lkdtm_kernel_info);     \
0052             break;                  \
0053         }                       \
0054     }                           \
0055 } while (0)
0056 #else
0057 #define pr_expected_config_param(kconfig, param) pr_expected_config(kconfig)
0058 #endif
0059 
0060 /* Crash types. */
0061 struct crashtype {
0062     const char *name;
0063     void (*func)(void);
0064 };
0065 
0066 #define CRASHTYPE(_name)            \
0067     {                   \
0068         .name = __stringify(_name), \
0069         .func = lkdtm_ ## _name,    \
0070     }
0071 
0072 /* Category's collection of crashtypes. */
0073 struct crashtype_category {
0074     struct crashtype *crashtypes;
0075     size_t len;
0076 };
0077 
0078 /* Each category's crashtypes list. */
0079 extern struct crashtype_category bugs_crashtypes;
0080 extern struct crashtype_category heap_crashtypes;
0081 extern struct crashtype_category perms_crashtypes;
0082 extern struct crashtype_category refcount_crashtypes;
0083 extern struct crashtype_category usercopy_crashtypes;
0084 extern struct crashtype_category stackleak_crashtypes;
0085 extern struct crashtype_category cfi_crashtypes;
0086 extern struct crashtype_category fortify_crashtypes;
0087 extern struct crashtype_category powerpc_crashtypes;
0088 
0089 /* Each category's init/exit routines. */
0090 void __init lkdtm_bugs_init(int *recur_param);
0091 void __init lkdtm_heap_init(void);
0092 void __exit lkdtm_heap_exit(void);
0093 void __init lkdtm_perms_init(void);
0094 void __init lkdtm_usercopy_init(void);
0095 void __exit lkdtm_usercopy_exit(void);
0096 
0097 /* Special declaration for function-in-rodata. */
0098 void lkdtm_rodata_do_nothing(void);
0099 
0100 #endif