blob: 4b9f85c963d0738e20ee7c89e2dcb28ba3cc1aaa [file] [log] [blame]
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08001#ifndef _LINUX_KASAN_H
2#define _LINUX_KASAN_H
3
4#include <linux/types.h>
5
6struct kmem_cache;
7struct page;
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -07008struct vm_struct;
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08009
10#ifdef CONFIG_KASAN
11
12#define KASAN_SHADOW_SCALE_SHIFT 3
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080013
14#include <asm/kasan.h>
Andrey Ryabinin69786cdb2015-08-13 08:37:24 +030015#include <asm/pgtable.h>
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080016#include <linux/sched.h>
17
Andrey Ryabinin69786cdb2015-08-13 08:37:24 +030018extern unsigned char kasan_zero_page[PAGE_SIZE];
19extern pte_t kasan_zero_pte[PTRS_PER_PTE];
20extern pmd_t kasan_zero_pmd[PTRS_PER_PMD];
21extern pud_t kasan_zero_pud[PTRS_PER_PUD];
22
23void kasan_populate_zero_shadow(const void *shadow_start,
24 const void *shadow_end);
25
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080026static inline void *kasan_mem_to_shadow(const void *addr)
27{
28 return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT)
29 + KASAN_SHADOW_OFFSET;
30}
31
32/* Enable reporting bugs after kasan_disable_current() */
33static inline void kasan_enable_current(void)
34{
35 current->kasan_depth++;
36}
37
38/* Disable reporting bugs for current task */
39static inline void kasan_disable_current(void)
40{
41 current->kasan_depth--;
42}
43
44void kasan_unpoison_shadow(const void *address, size_t size);
45
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080046void kasan_alloc_pages(struct page *page, unsigned int order);
47void kasan_free_pages(struct page *page, unsigned int order);
48
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080049void kasan_poison_slab(struct page *page);
50void kasan_unpoison_object_data(struct kmem_cache *cache, void *object);
51void kasan_poison_object_data(struct kmem_cache *cache, void *object);
52
53void kasan_kmalloc_large(const void *ptr, size_t size);
54void kasan_kfree_large(const void *ptr);
Andrey Ryabinin92393612015-04-15 16:15:05 -070055void kasan_kfree(void *ptr);
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080056void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size);
57void kasan_krealloc(const void *object, size_t new_size);
58
59void kasan_slab_alloc(struct kmem_cache *s, void *object);
60void kasan_slab_free(struct kmem_cache *s, void *object);
61
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080062int kasan_module_alloc(void *addr, size_t size);
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070063void kasan_free_shadow(const struct vm_struct *vm);
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080064
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080065#else /* CONFIG_KASAN */
66
67static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
68
69static inline void kasan_enable_current(void) {}
70static inline void kasan_disable_current(void) {}
71
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080072static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
73static inline void kasan_free_pages(struct page *page, unsigned int order) {}
74
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080075static inline void kasan_poison_slab(struct page *page) {}
76static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
77 void *object) {}
78static inline void kasan_poison_object_data(struct kmem_cache *cache,
79 void *object) {}
80
81static inline void kasan_kmalloc_large(void *ptr, size_t size) {}
82static inline void kasan_kfree_large(const void *ptr) {}
Andrey Ryabinin92393612015-04-15 16:15:05 -070083static inline void kasan_kfree(void *ptr) {}
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080084static inline void kasan_kmalloc(struct kmem_cache *s, const void *object,
85 size_t size) {}
86static inline void kasan_krealloc(const void *object, size_t new_size) {}
87
88static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
89static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
90
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080091static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070092static inline void kasan_free_shadow(const struct vm_struct *vm) {}
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080093
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080094#endif /* CONFIG_KASAN */
95
96#endif /* LINUX_KASAN_H */