lkdtm.h 3.0 KB

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