1 #ifndef _LINUX_KASAN_H 2 #define _LINUX_KASAN_H 3 4 #include <linux/types.h> 5 6 struct kmem_cache; 7 struct page; 8 struct vm_struct; 9 10 #ifdef CONFIG_KASAN 11 12 #define KASAN_SHADOW_SCALE_SHIFT 3 13 #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) 14 15 #include <asm/kasan.h> 16 #include <linux/sched.h> 17 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 24 /* Enable reporting bugs after kasan_disable_current() */ 25 static inline void kasan_enable_current(void) 26 { 27 current->kasan_depth++; 28 } 29 30 /* Disable reporting bugs for current task */ 31 static inline void kasan_disable_current(void) 32 { 33 current->kasan_depth--; 34 } 35 36 void kasan_unpoison_shadow(const void *address, size_t size); 37 38 void kasan_alloc_pages(struct page *page, unsigned int order); 39 void kasan_free_pages(struct page *page, unsigned int order); 40 41 void kasan_poison_slab(struct page *page); 42 void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); 43 void kasan_poison_object_data(struct kmem_cache *cache, void *object); 44 45 void kasan_kmalloc_large(const void *ptr, size_t size); 46 void kasan_kfree_large(const void *ptr); 47 void kasan_kfree(void *ptr); 48 void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size); 49 void kasan_krealloc(const void *object, size_t new_size); 50 51 void kasan_slab_alloc(struct kmem_cache *s, void *object); 52 void kasan_slab_free(struct kmem_cache *s, void *object); 53 54 int kasan_module_alloc(void *addr, size_t size); 55 void kasan_free_shadow(const struct vm_struct *vm); 56 57 #else /* CONFIG_KASAN */ 58 59 static inline void kasan_unpoison_shadow(const void *address, size_t size) {} 60 61 static inline void kasan_enable_current(void) {} 62 static inline void kasan_disable_current(void) {} 63 64 static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} 65 static inline void kasan_free_pages(struct page *page, unsigned int order) {} 66 67 static inline void kasan_poison_slab(struct page *page) {} 68 static inline void kasan_unpoison_object_data(struct kmem_cache *cache, 69 void *object) {} 70 static inline void kasan_poison_object_data(struct kmem_cache *cache, 71 void *object) {} 72 73 static inline void kasan_kmalloc_large(void *ptr, size_t size) {} 74 static inline void kasan_kfree_large(const void *ptr) {} 75 static inline void kasan_kfree(void *ptr) {} 76 static inline void kasan_kmalloc(struct kmem_cache *s, const void *object, 77 size_t size) {} 78 static inline void kasan_krealloc(const void *object, size_t new_size) {} 79 80 static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {} 81 static inline void kasan_slab_free(struct kmem_cache *s, void *object) {} 82 83 static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } 84 static inline void kasan_free_shadow(const struct vm_struct *vm) {} 85 86 #endif /* CONFIG_KASAN */ 87 88 #endif /* LINUX_KASAN_H */ 89