blob: 5486d777b706edeb20db7782e27ff12b6a558945 [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
13#define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL)
14
15#include <asm/kasan.h>
16#include <linux/sched.h>
17
18static 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() */
25static inline void kasan_enable_current(void)
26{
27 current->kasan_depth++;
28}
29
30/* Disable reporting bugs for current task */
31static inline void kasan_disable_current(void)
32{
33 current->kasan_depth--;
34}
35
36void kasan_unpoison_shadow(const void *address, size_t size);
37
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080038void kasan_alloc_pages(struct page *page, unsigned int order);
39void kasan_free_pages(struct page *page, unsigned int order);
40
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080041void kasan_poison_slab(struct page *page);
42void kasan_unpoison_object_data(struct kmem_cache *cache, void *object);
43void kasan_poison_object_data(struct kmem_cache *cache, void *object);
44
45void kasan_kmalloc_large(const void *ptr, size_t size);
46void kasan_kfree_large(const void *ptr);
Andrey Ryabinin92393612015-04-15 16:15:05 -070047void kasan_kfree(void *ptr);
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080048void kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size);
49void kasan_krealloc(const void *object, size_t new_size);
50
51void kasan_slab_alloc(struct kmem_cache *s, void *object);
52void kasan_slab_free(struct kmem_cache *s, void *object);
53
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080054int kasan_module_alloc(void *addr, size_t size);
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070055void kasan_free_shadow(const struct vm_struct *vm);
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080056
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080057#else /* CONFIG_KASAN */
58
59static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
60
61static inline void kasan_enable_current(void) {}
62static inline void kasan_disable_current(void) {}
63
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080064static inline void kasan_alloc_pages(struct page *page, unsigned int order) {}
65static inline void kasan_free_pages(struct page *page, unsigned int order) {}
66
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080067static inline void kasan_poison_slab(struct page *page) {}
68static inline void kasan_unpoison_object_data(struct kmem_cache *cache,
69 void *object) {}
70static inline void kasan_poison_object_data(struct kmem_cache *cache,
71 void *object) {}
72
73static inline void kasan_kmalloc_large(void *ptr, size_t size) {}
74static inline void kasan_kfree_large(const void *ptr) {}
Andrey Ryabinin92393612015-04-15 16:15:05 -070075static inline void kasan_kfree(void *ptr) {}
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080076static inline void kasan_kmalloc(struct kmem_cache *s, const void *object,
77 size_t size) {}
78static inline void kasan_krealloc(const void *object, size_t new_size) {}
79
80static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
81static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
82
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080083static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
Andrey Ryabinina5af5aa2015-03-12 16:26:11 -070084static inline void kasan_free_shadow(const struct vm_struct *vm) {}
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080085
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080086#endif /* CONFIG_KASAN */
87
88#endif /* LINUX_KASAN_H */