10b24beccSAndrey Ryabinin #ifndef _LINUX_KASAN_H 20b24beccSAndrey Ryabinin #define _LINUX_KASAN_H 30b24beccSAndrey Ryabinin 40b24beccSAndrey Ryabinin #include <linux/types.h> 50b24beccSAndrey Ryabinin 60b24beccSAndrey Ryabinin struct kmem_cache; 70b24beccSAndrey Ryabinin struct page; 8a5af5aa8SAndrey Ryabinin struct vm_struct; 90b24beccSAndrey Ryabinin 100b24beccSAndrey Ryabinin #ifdef CONFIG_KASAN 110b24beccSAndrey Ryabinin 120b24beccSAndrey Ryabinin #define KASAN_SHADOW_SCALE_SHIFT 3 130b24beccSAndrey Ryabinin #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) 140b24beccSAndrey Ryabinin 150b24beccSAndrey Ryabinin #include <asm/kasan.h> 160b24beccSAndrey Ryabinin #include <linux/sched.h> 170b24beccSAndrey Ryabinin 180b24beccSAndrey Ryabinin static inline void *kasan_mem_to_shadow(const void *addr) 190b24beccSAndrey Ryabinin { 200b24beccSAndrey Ryabinin return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) 210b24beccSAndrey Ryabinin + KASAN_SHADOW_OFFSET; 220b24beccSAndrey Ryabinin } 230b24beccSAndrey Ryabinin 240b24beccSAndrey Ryabinin /* Enable reporting bugs after kasan_disable_current() */ 250b24beccSAndrey Ryabinin static inline void kasan_enable_current(void) 260b24beccSAndrey Ryabinin { 270b24beccSAndrey Ryabinin current->kasan_depth++; 280b24beccSAndrey Ryabinin } 290b24beccSAndrey Ryabinin 300b24beccSAndrey Ryabinin /* Disable reporting bugs for current task */ 310b24beccSAndrey Ryabinin static inline void kasan_disable_current(void) 320b24beccSAndrey Ryabinin { 330b24beccSAndrey Ryabinin current->kasan_depth--; 340b24beccSAndrey Ryabinin } 350b24beccSAndrey Ryabinin 360b24beccSAndrey Ryabinin void kasan_unpoison_shadow(const void *address, size_t size); 370b24beccSAndrey Ryabinin 38b8c73fc2SAndrey Ryabinin void kasan_alloc_pages(struct page *page, unsigned int order); 39b8c73fc2SAndrey Ryabinin void kasan_free_pages(struct page *page, unsigned int order); 40b8c73fc2SAndrey Ryabinin 410316bec2SAndrey Ryabinin void kasan_poison_slab(struct page *page); 420316bec2SAndrey Ryabinin void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); 430316bec2SAndrey Ryabinin void kasan_poison_object_data(struct kmem_cache *cache, void *object); 440316bec2SAndrey Ryabinin 450316bec2SAndrey Ryabinin void kasan_kmalloc_large(const void *ptr, size_t size); 460316bec2SAndrey Ryabinin void kasan_kfree_large(const void *ptr); 4792393615SAndrey Ryabinin void kasan_kfree(void *ptr); 480316bec2SAndrey Ryabinin void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size); 490316bec2SAndrey Ryabinin void kasan_krealloc(const void *object, size_t new_size); 500316bec2SAndrey Ryabinin 510316bec2SAndrey Ryabinin void kasan_slab_alloc(struct kmem_cache *s, void *object); 520316bec2SAndrey Ryabinin void kasan_slab_free(struct kmem_cache *s, void *object); 530316bec2SAndrey Ryabinin 54bebf56a1SAndrey Ryabinin int kasan_module_alloc(void *addr, size_t size); 55a5af5aa8SAndrey Ryabinin void kasan_free_shadow(const struct vm_struct *vm); 56bebf56a1SAndrey Ryabinin 570b24beccSAndrey Ryabinin #else /* CONFIG_KASAN */ 580b24beccSAndrey Ryabinin 590b24beccSAndrey Ryabinin static inline void kasan_unpoison_shadow(const void *address, size_t size) {} 600b24beccSAndrey Ryabinin 610b24beccSAndrey Ryabinin static inline void kasan_enable_current(void) {} 620b24beccSAndrey Ryabinin static inline void kasan_disable_current(void) {} 630b24beccSAndrey Ryabinin 64b8c73fc2SAndrey Ryabinin static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} 65b8c73fc2SAndrey Ryabinin static inline void kasan_free_pages(struct page *page, unsigned int order) {} 66b8c73fc2SAndrey Ryabinin 670316bec2SAndrey Ryabinin static inline void kasan_poison_slab(struct page *page) {} 680316bec2SAndrey Ryabinin static inline void kasan_unpoison_object_data(struct kmem_cache *cache, 690316bec2SAndrey Ryabinin void *object) {} 700316bec2SAndrey Ryabinin static inline void kasan_poison_object_data(struct kmem_cache *cache, 710316bec2SAndrey Ryabinin void *object) {} 720316bec2SAndrey Ryabinin 730316bec2SAndrey Ryabinin static inline void kasan_kmalloc_large(void *ptr, size_t size) {} 740316bec2SAndrey Ryabinin static inline void kasan_kfree_large(const void *ptr) {} 7592393615SAndrey Ryabinin static inline void kasan_kfree(void *ptr) {} 760316bec2SAndrey Ryabinin static inline void kasan_kmalloc(struct kmem_cache *s, const void *object, 770316bec2SAndrey Ryabinin size_t size) {} 780316bec2SAndrey Ryabinin static inline void kasan_krealloc(const void *object, size_t new_size) {} 790316bec2SAndrey Ryabinin 800316bec2SAndrey Ryabinin static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {} 810316bec2SAndrey Ryabinin static inline void kasan_slab_free(struct kmem_cache *s, void *object) {} 820316bec2SAndrey Ryabinin 83bebf56a1SAndrey Ryabinin static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } 84a5af5aa8SAndrey Ryabinin static inline void kasan_free_shadow(const struct vm_struct *vm) {} 85bebf56a1SAndrey Ryabinin 860b24beccSAndrey Ryabinin #endif /* CONFIG_KASAN */ 870b24beccSAndrey Ryabinin 880b24beccSAndrey Ryabinin #endif /* LINUX_KASAN_H */ 89