xref: /freebsd/sys/sys/asan.h (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
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  * $FreeBSD$
31  */
32 
33 #ifndef _SYS_ASAN_H_
34 #define _SYS_ASAN_H_
35 
36 #ifdef KASAN
37 #include <sys/types.h>
38 
39 /* ASAN constants. Part of the compiler ABI. */
40 #define KASAN_SHADOW_SCALE		8
41 #define KASAN_SHADOW_SCALE_SHIFT	3
42 
43 /* Stack redzone values. Part of the compiler ABI. */
44 #define KASAN_STACK_LEFT	0xF1
45 #define KASAN_STACK_MID		0xF2
46 #define KASAN_STACK_RIGHT	0xF3
47 #define KASAN_USE_AFTER_RET	0xF5
48 #define KASAN_USE_AFTER_SCOPE	0xF8
49 
50 /* Our redzone values. */
51 #define KASAN_GENERIC_REDZONE	0xFA
52 #define KASAN_MALLOC_REDZONE	0xFB
53 #define KASAN_KMEM_REDZONE	0xFC
54 #define	KASAN_UMA_FREED		0xFD
55 #define	KASAN_KSTACK_FREED	0xFE
56 #define	KASAN_EXEC_ARGS_FREED	0xFF
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 #else /* KASAN */
63 #define kasan_init()
64 #define kasan_shadow_map(a, s)
65 #define kasan_mark(p, s, l, c)
66 #endif /* !KASAN */
67 
68 #endif /* !_SYS_ASAN_H_ */
69