138da497aSMark Johnston /* $NetBSD: asan.h,v 1.15 2020/09/10 14:10:46 maxv Exp $ */ 238da497aSMark Johnston 338da497aSMark Johnston /* 438da497aSMark Johnston * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net 538da497aSMark Johnston * All rights reserved. 638da497aSMark Johnston * 738da497aSMark Johnston * This code is part of the KASAN subsystem of the NetBSD kernel. 838da497aSMark Johnston * 938da497aSMark Johnston * Redistribution and use in source and binary forms, with or without 1038da497aSMark Johnston * modification, are permitted provided that the following conditions 1138da497aSMark Johnston * are met: 1238da497aSMark Johnston * 1. Redistributions of source code must retain the above copyright 1338da497aSMark Johnston * notice, this list of conditions and the following disclaimer. 1438da497aSMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 1538da497aSMark Johnston * notice, this list of conditions and the following disclaimer in the 1638da497aSMark Johnston * documentation and/or other materials provided with the distribution. 1738da497aSMark Johnston * 1838da497aSMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1938da497aSMark Johnston * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2038da497aSMark Johnston * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2138da497aSMark Johnston * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2238da497aSMark Johnston * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2338da497aSMark Johnston * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2438da497aSMark Johnston * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2538da497aSMark Johnston * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2638da497aSMark Johnston * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2738da497aSMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2838da497aSMark Johnston * SUCH DAMAGE. 2938da497aSMark Johnston */ 3038da497aSMark Johnston 3138da497aSMark Johnston #ifndef _SYS_ASAN_H_ 3238da497aSMark Johnston #define _SYS_ASAN_H_ 3338da497aSMark Johnston 3438da497aSMark Johnston #ifdef KASAN 3538da497aSMark Johnston #include <sys/types.h> 3638da497aSMark Johnston 3738da497aSMark Johnston /* ASAN constants. Part of the compiler ABI. */ 3838da497aSMark Johnston #define KASAN_SHADOW_SCALE 8 3938da497aSMark Johnston #define KASAN_SHADOW_SCALE_SHIFT 3 4038da497aSMark Johnston 4138da497aSMark Johnston /* Stack redzone values. Part of the compiler ABI. */ 4238da497aSMark Johnston #define KASAN_STACK_LEFT 0xF1 4338da497aSMark Johnston #define KASAN_STACK_MID 0xF2 4438da497aSMark Johnston #define KASAN_STACK_RIGHT 0xF3 4538da497aSMark Johnston #define KASAN_USE_AFTER_RET 0xF5 4638da497aSMark Johnston #define KASAN_USE_AFTER_SCOPE 0xF8 4738da497aSMark Johnston 4838da497aSMark Johnston /* Our redzone values. */ 4938da497aSMark Johnston #define KASAN_GENERIC_REDZONE 0xFA 5038da497aSMark Johnston #define KASAN_MALLOC_REDZONE 0xFB 5138da497aSMark Johnston #define KASAN_KMEM_REDZONE 0xFC 5238da497aSMark Johnston #define KASAN_UMA_FREED 0xFD 5338da497aSMark Johnston #define KASAN_KSTACK_FREED 0xFE 54f1c3adefSMark Johnston #define KASAN_EXEC_ARGS_FREED 0xFF 5538da497aSMark Johnston 56*800da341SMark Johnston struct thread; 57*800da341SMark Johnston 5838da497aSMark Johnston void kasan_init(void); 59756bc3adSMark Johnston void kasan_init_early(vm_offset_t, size_t); 6020e3b9d8SMark Johnston void kasan_shadow_map(vm_offset_t, size_t); 6138da497aSMark Johnston void kasan_mark(const void *, size_t, size_t, uint8_t); 62*800da341SMark Johnston void kasan_thread_alloc(struct thread *); 6338da497aSMark Johnston #else /* KASAN */ 6438da497aSMark Johnston #define kasan_init() 6538da497aSMark Johnston #define kasan_shadow_map(a, s) 6638da497aSMark Johnston #define kasan_mark(p, s, l, c) 67*800da341SMark Johnston #define kasan_thread_alloc(t) 6838da497aSMark Johnston #endif /* !KASAN */ 6938da497aSMark Johnston 7038da497aSMark Johnston #endif /* !_SYS_ASAN_H_ */ 71