xref: /freebsd/sys/sys/asan.h (revision 96190b4fef3b4a0cc3ca0606b0c4e3e69a5e6717)
1 /*	$NetBSD: asan.h,v 1.15 2020/09/10 14:10:46 maxv Exp $	*/
2 
3 /*
4  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
5  * All rights reserved.
6  *
7  * This code is part of the KASAN subsystem of the NetBSD kernel.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef _SYS_ASAN_H_
32 #define _SYS_ASAN_H_
33 
34 #ifdef KASAN
35 #include <sys/types.h>
36 
37 /* ASAN constants. Part of the compiler ABI. */
38 #define KASAN_SHADOW_SCALE		8
39 #define KASAN_SHADOW_SCALE_SHIFT	3
40 
41 /* Stack redzone values. Part of the compiler ABI. */
42 #define KASAN_STACK_LEFT	0xF1
43 #define KASAN_STACK_MID		0xF2
44 #define KASAN_STACK_RIGHT	0xF3
45 #define KASAN_USE_AFTER_RET	0xF5
46 #define KASAN_USE_AFTER_SCOPE	0xF8
47 
48 /* Our redzone values. */
49 #define KASAN_GENERIC_REDZONE	0xFA
50 #define KASAN_MALLOC_REDZONE	0xFB
51 #define KASAN_KMEM_REDZONE	0xFC
52 #define	KASAN_UMA_FREED		0xFD
53 #define	KASAN_KSTACK_FREED	0xFE
54 #define	KASAN_EXEC_ARGS_FREED	0xFF
55 
56 struct thread;
57 
58 void kasan_init(void);
59 void kasan_init_early(vm_offset_t, size_t);
60 void kasan_shadow_map(vm_offset_t, size_t);
61 void kasan_mark(const void *, size_t, size_t, uint8_t);
62 void kasan_thread_alloc(struct thread *);
63 #else /* KASAN */
64 #define kasan_init()
65 #define kasan_shadow_map(a, s)
66 #define kasan_mark(p, s, l, c)
67 #define kasan_thread_alloc(t)
68 #endif /* !KASAN */
69 
70 #endif /* !_SYS_ASAN_H_ */
71