kasan.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef _LINUX_KASAN_H
  2. #define _LINUX_KASAN_H
  3. #include <linux/types.h>
  4. struct kmem_cache;
  5. struct page;
  6. struct vm_struct;
  7. #ifdef CONFIG_KASAN
  8. #define KASAN_SHADOW_SCALE_SHIFT 3
  9. #include <asm/kasan.h>
  10. #include <asm/pgtable.h>
  11. #include <linux/sched.h>
  12. extern unsigned char kasan_zero_page[PAGE_SIZE];
  13. extern pte_t kasan_zero_pte[PTRS_PER_PTE];
  14. extern pmd_t kasan_zero_pmd[PTRS_PER_PMD];
  15. extern pud_t kasan_zero_pud[PTRS_PER_PUD];
  16. void kasan_populate_zero_shadow(const void *shadow_start,
  17. const void *shadow_end);
  18. static inline void *kasan_mem_to_shadow(const void *addr)
  19. {
  20. return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
  21. + KASAN_SHADOW_OFFSET;
  22. }
  23. /* Enable reporting bugs after kasan_disable_current() */
  24. static inline void kasan_enable_current(void)
  25. {
  26. current->kasan_depth++;
  27. }
  28. /* Disable reporting bugs for current task */
  29. static inline void kasan_disable_current(void)
  30. {
  31. current->kasan_depth--;
  32. }
  33. void kasan_unpoison_shadow(const void *address, size_t size);
  34. void kasan_alloc_pages(struct page *page, unsigned int order);
  35. void kasan_free_pages(struct page *page, unsigned int order);
  36. void kasan_poison_slab(struct page *page);
  37. void kasan_unpoison_object_data(struct kmem_cache *cache, void *object);
  38. void kasan_poison_object_data(struct kmem_cache *cache, void *object);
  39. void kasan_kmalloc_large(const void *ptr, size_t size);
  40. void kasan_kfree_large(const void *ptr);
  41. void kasan_kfree(void *ptr);
  42. void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size);
  43. void kasan_krealloc(const void *object, size_t new_size);
  44. void kasan_slab_alloc(struct kmem_cache *s, void *object);
  45. void kasan_slab_free(struct kmem_cache *s, void *object);
  46. int kasan_module_alloc(void *addr, size_t size);
  47. void kasan_free_shadow(const struct vm_struct *vm);
  48. #else /* CONFIG_KASAN */
  49. static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
  50. static inline void kasan_enable_current(void) {}
  51. static inline void kasan_disable_current(void) {}
  52. static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
  53. static inline void kasan_free_pages(struct page *page, unsigned int order) {}
  54. static inline void kasan_poison_slab(struct page *page) {}
  55. static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
  56. void *object) {}
  57. static inline void kasan_poison_object_data(struct kmem_cache *cache,
  58. void *object) {}
  59. static inline void kasan_kmalloc_large(void *ptr, size_t size) {}
  60. static inline void kasan_kfree_large(const void *ptr) {}
  61. static inline void kasan_kfree(void *ptr) {}
  62. static inline void kasan_kmalloc(struct kmem_cache *s, const void *object,
  63. size_t size) {}
  64. static inline void kasan_krealloc(const void *object, size_t new_size) {}
  65. static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
  66. static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
  67. static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
  68. static inline void kasan_free_shadow(const struct vm_struct *vm) {}
  69. #endif /* CONFIG_KASAN */
  70. #endif /* LINUX_KASAN_H */