xref: /netbsd-src/sys/sys/asan.h (revision b813e1084f8f814e24e4e8f84e5f0740f744f229)
1*b813e108Smaxv /*	$NetBSD: asan.h,v 1.15 2020/09/10 14:10:46 maxv Exp $	*/
2acb25765Smaxv 
3acb25765Smaxv /*
4*b813e108Smaxv  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
5acb25765Smaxv  * All rights reserved.
6acb25765Smaxv  *
7*b813e108Smaxv  * This code is part of the KASAN subsystem of the NetBSD kernel.
8acb25765Smaxv  *
9acb25765Smaxv  * Redistribution and use in source and binary forms, with or without
10acb25765Smaxv  * modification, are permitted provided that the following conditions
11acb25765Smaxv  * are met:
12acb25765Smaxv  * 1. Redistributions of source code must retain the above copyright
13acb25765Smaxv  *    notice, this list of conditions and the following disclaimer.
14acb25765Smaxv  * 2. Redistributions in binary form must reproduce the above copyright
15acb25765Smaxv  *    notice, this list of conditions and the following disclaimer in the
16acb25765Smaxv  *    documentation and/or other materials provided with the distribution.
17acb25765Smaxv  *
18*b813e108Smaxv  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*b813e108Smaxv  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*b813e108Smaxv  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*b813e108Smaxv  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*b813e108Smaxv  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23*b813e108Smaxv  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24*b813e108Smaxv  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25*b813e108Smaxv  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26*b813e108Smaxv  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*b813e108Smaxv  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*b813e108Smaxv  * SUCH DAMAGE.
29acb25765Smaxv  */
30acb25765Smaxv 
31acb25765Smaxv #ifndef _SYS_ASAN_H_
32acb25765Smaxv #define _SYS_ASAN_H_
33acb25765Smaxv 
34daac7774Schristos #ifdef _KERNEL_OPT
35daac7774Schristos #include "opt_kasan.h"
36daac7774Schristos #endif
37daac7774Schristos 
3836beaf9dSmaxv #ifdef KASAN
39acb25765Smaxv #include <sys/types.h>
4036beaf9dSmaxv #include <sys/bus.h>
41acb25765Smaxv 
42bd9956fcSskrll /* ASAN constants. Part of the compiler ABI. */
43bd9956fcSskrll #define KASAN_SHADOW_SCALE_SHIFT	3
44bd9956fcSskrll 
45ae73490eSmaxv /* Stack redzone values. Part of the compiler ABI. */
46ae73490eSmaxv #define KASAN_STACK_LEFT	0xF1
47ae73490eSmaxv #define KASAN_STACK_MID		0xF2
48ae73490eSmaxv #define KASAN_STACK_RIGHT	0xF3
49740b83a3Smaxv #define KASAN_USE_AFTER_RET	0xF5
50ae73490eSmaxv #define KASAN_USE_AFTER_SCOPE	0xF8
51ae73490eSmaxv 
52ae73490eSmaxv /* Our redzone values. */
53ae73490eSmaxv #define KASAN_GENERIC_REDZONE	0xFA
54ae73490eSmaxv #define KASAN_MALLOC_REDZONE	0xFB
55ae73490eSmaxv #define KASAN_KMEM_REDZONE	0xFC
56ae73490eSmaxv #define KASAN_POOL_REDZONE	0xFD
57ae73490eSmaxv #define KASAN_POOL_FREED	0xFE
58ae73490eSmaxv 
5936beaf9dSmaxv /* DMA types. */
6036beaf9dSmaxv #define KASAN_DMA_LINEAR	1
6136beaf9dSmaxv #define KASAN_DMA_MBUF		2
6236beaf9dSmaxv #define KASAN_DMA_UIO		3
6336beaf9dSmaxv #define KASAN_DMA_RAW		4
6436beaf9dSmaxv 
65790d0b79Smaxv void kasan_early_init(void *);
66790d0b79Smaxv void kasan_init(void);
678a98cb54Smaxv void kasan_shadow_map(void *, size_t);
688a98cb54Smaxv 
69790d0b79Smaxv void kasan_softint(struct lwp *);
70790d0b79Smaxv 
7136beaf9dSmaxv void kasan_dma_sync(bus_dmamap_t, bus_addr_t, bus_size_t, int);
7236beaf9dSmaxv void kasan_dma_load(bus_dmamap_t, void *, bus_size_t, int);
7336beaf9dSmaxv 
74acb25765Smaxv void kasan_add_redzone(size_t *);
75ae73490eSmaxv void kasan_mark(const void *, size_t, size_t, uint8_t);
767f4e877eSmaxv #else
778a98cb54Smaxv #define kasan_early_init(u)		__nothing
788a98cb54Smaxv #define kasan_init()			__nothing
798a98cb54Smaxv #define kasan_shadow_map(a, s)		__nothing
8036beaf9dSmaxv #define kasan_dma_sync(m, a, s, o)	__nothing
8136beaf9dSmaxv #define kasan_dma_load(m, b, s, o)	__nothing
82daac7774Schristos #define kasan_add_redzone(s)		__nothing
83ae73490eSmaxv #define kasan_mark(p, s, l, c)		__nothing
847f4e877eSmaxv #endif
85acb25765Smaxv 
86acb25765Smaxv #endif /* !_SYS_ASAN_H_ */
87