Home | History | Annotate | Line # | Download | only in sys
      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 _KERNEL_OPT
     35 #include "opt_kasan.h"
     36 #endif
     37 
     38 #ifdef KASAN
     39 #include <sys/types.h>
     40 #include <sys/bus.h>
     41 
     42 /* ASAN constants. Part of the compiler ABI. */
     43 #define KASAN_SHADOW_SCALE_SHIFT	3
     44 
     45 /* Stack redzone values. Part of the compiler ABI. */
     46 #define KASAN_STACK_LEFT	0xF1
     47 #define KASAN_STACK_MID		0xF2
     48 #define KASAN_STACK_RIGHT	0xF3
     49 #define KASAN_USE_AFTER_RET	0xF5
     50 #define KASAN_USE_AFTER_SCOPE	0xF8
     51 
     52 /* Our redzone values. */
     53 #define KASAN_GENERIC_REDZONE	0xFA
     54 #define KASAN_MALLOC_REDZONE	0xFB
     55 #define KASAN_KMEM_REDZONE	0xFC
     56 #define KASAN_POOL_REDZONE	0xFD
     57 #define KASAN_POOL_FREED	0xFE
     58 
     59 /* DMA types. */
     60 #define KASAN_DMA_LINEAR	1
     61 #define KASAN_DMA_MBUF		2
     62 #define KASAN_DMA_UIO		3
     63 #define KASAN_DMA_RAW		4
     64 
     65 void kasan_early_init(void *);
     66 void kasan_init(void);
     67 void kasan_shadow_map(void *, size_t);
     68 
     69 void kasan_softint(struct lwp *);
     70 
     71 void kasan_dma_sync(bus_dmamap_t, bus_addr_t, bus_size_t, int);
     72 void kasan_dma_load(bus_dmamap_t, void *, bus_size_t, int);
     73 
     74 void kasan_add_redzone(size_t *);
     75 void kasan_mark(const void *, size_t, size_t, uint8_t);
     76 #else
     77 #define kasan_early_init(u)		__nothing
     78 #define kasan_init()			__nothing
     79 #define kasan_shadow_map(a, s)		__nothing
     80 #define kasan_dma_sync(m, a, s, o)	__nothing
     81 #define kasan_dma_load(m, b, s, o)	__nothing
     82 #define kasan_add_redzone(s)		__nothing
     83 #define kasan_mark(p, s, l, c)		__nothing
     84 #endif
     85 
     86 #endif /* !_SYS_ASAN_H_ */
     87