blob: 0fdc798e3ff795a9dffd75e36e90ce2b61141562 [file] [log] [blame]
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08001#ifndef _LINUX_KASAN_H
2#define _LINUX_KASAN_H
3
Mark Rutlande3ae1162016-03-09 14:08:15 -08004#include <linux/sched.h>
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08005#include <linux/types.h>
6
7struct kmem_cache;
8struct page;
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -07009struct vm_struct;
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080010
11#ifdef CONFIG_KASAN
12
13#define KASAN_SHADOW_SCALE_SHIFT 3
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080014
15#include <asm/kasan.h>
Andrey Ryabinin69786cdb2015-08-13 08:37:24 +030016#include <asm/pgtable.h>
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080017
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
Mark Rutlande3ae1162016-03-09 14:08:15 -080046void kasan_unpoison_task_stack(struct task_struct *task);
47
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080048void kasan_alloc_pages(struct page *page, unsigned int order);
49void kasan_free_pages(struct page *page, unsigned int order);
50
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080051void kasan_poison_slab(struct page *page);
52void kasan_unpoison_object_data(struct kmem_cache *cache, void *object);
53void kasan_poison_object_data(struct kmem_cache *cache, void *object);
54
55void kasan_kmalloc_large(const void *ptr, size_t size);
56void kasan_kfree_large(const void *ptr);
Andrey Ryabinin92393612015-04-15 16:15:05 -070057void kasan_kfree(void *ptr);
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080058void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size);
59void kasan_krealloc(const void *object, size_t new_size);
60
61void kasan_slab_alloc(struct kmem_cache *s, void *object);
62void kasan_slab_free(struct kmem_cache *s, void *object);
63
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080064int kasan_module_alloc(void *addr, size_t size);
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070065void kasan_free_shadow(const struct vm_struct *vm);
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080066
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080067#else /* CONFIG_KASAN */
68
69static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
70
Mark Rutlande3ae1162016-03-09 14:08:15 -080071static inline void kasan_unpoison_task_stack(struct task_struct *task) {}
72
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080073static inline void kasan_enable_current(void) {}
74static inline void kasan_disable_current(void) {}
75
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080076static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
77static inline void kasan_free_pages(struct page *page, unsigned int order) {}
78
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080079static inline void kasan_poison_slab(struct page *page) {}
80static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
81 void *object) {}
82static inline void kasan_poison_object_data(struct kmem_cache *cache,
83 void *object) {}
84
85static inline void kasan_kmalloc_large(void *ptr, size_t size) {}
86static inline void kasan_kfree_large(const void *ptr) {}
Andrey Ryabinin92393612015-04-15 16:15:05 -070087static inline void kasan_kfree(void *ptr) {}
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080088static inline void kasan_kmalloc(struct kmem_cache *s, const void *object,
89 size_t size) {}
90static inline void kasan_krealloc(const void *object, size_t new_size) {}
91
92static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
93static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
94
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080095static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070096static inline void kasan_free_shadow(const struct vm_struct *vm) {}
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080097
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080098#endif /* CONFIG_KASAN */
99
100#endif /* LINUX_KASAN_H */