kasan.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef __MM_KASAN_KASAN_H
  2. #define __MM_KASAN_KASAN_H
  3. #include <linux/kasan.h>
  4. #define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT)
  5. #define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1)
  6. #define KASAN_FREE_PAGE 0xFF /* page was freed */
  7. #define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */
  8. #define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */
  9. #define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */
  10. #define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */
  11. /*
  12. * Stack redzone shadow values
  13. * (Those are compiler's ABI, don't change them)
  14. */
  15. #define KASAN_STACK_LEFT 0xF1
  16. #define KASAN_STACK_MID 0xF2
  17. #define KASAN_STACK_RIGHT 0xF3
  18. #define KASAN_STACK_PARTIAL 0xF4
  19. /* Don't break randconfig/all*config builds */
  20. #ifndef KASAN_ABI_VERSION
  21. #define KASAN_ABI_VERSION 1
  22. #endif
  23. struct kasan_access_info {
  24. const void *access_addr;
  25. const void *first_bad_addr;
  26. size_t access_size;
  27. bool is_write;
  28. unsigned long ip;
  29. };
  30. /* The layout of struct dictated by compiler */
  31. struct kasan_source_location {
  32. const char *filename;
  33. int line_no;
  34. int column_no;
  35. };
  36. /* The layout of struct dictated by compiler */
  37. struct kasan_global {
  38. const void *beg; /* Address of the beginning of the global variable. */
  39. size_t size; /* Size of the global variable. */
  40. size_t size_with_redzone; /* Size of the variable + size of the red zone. 32 bytes aligned */
  41. const void *name;
  42. const void *module_name; /* Name of the module where the global variable is declared. */
  43. unsigned long has_dynamic_init; /* This needed for C++ */
  44. #if KASAN_ABI_VERSION >= 4
  45. struct kasan_source_location *location;
  46. #endif
  47. #if KASAN_ABI_VERSION >= 5
  48. char *odr_indicator;
  49. #endif
  50. };
  51. static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
  52. {
  53. return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
  54. << KASAN_SHADOW_SCALE_SHIFT);
  55. }
  56. static inline bool kasan_report_enabled(void)
  57. {
  58. return !current->kasan_depth;
  59. }
  60. void kasan_report(unsigned long addr, size_t size,
  61. bool is_write, unsigned long ip);
  62. #endif