| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: asan.h,v 1.6 2020/05/02 16:28:37 maxv Exp $ */ | | 1 | /* $NetBSD: asan.h,v 1.7 2020/06/23 17:21:55 maxv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Maxime Villard. | | 8 | * by Maxime Villard. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -32,27 +32,27 @@ | | | @@ -32,27 +32,27 @@ |
32 | #include <sys/ksyms.h> | | 32 | #include <sys/ksyms.h> |
33 | | | 33 | |
34 | #include <amd64/pmap.h> | | 34 | #include <amd64/pmap.h> |
35 | #include <amd64/vmparam.h> | | 35 | #include <amd64/vmparam.h> |
36 | | | 36 | |
37 | #ifdef __HAVE_PCPU_AREA | | 37 | #ifdef __HAVE_PCPU_AREA |
38 | #error "PCPU area not allowed with KASAN" | | 38 | #error "PCPU area not allowed with KASAN" |
39 | #endif | | 39 | #endif |
40 | #ifdef __HAVE_DIRECT_MAP | | 40 | #ifdef __HAVE_DIRECT_MAP |
41 | #error "DMAP not allowed with KASAN" | | 41 | #error "DMAP not allowed with KASAN" |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #define __MD_VIRTUAL_SHIFT 47 /* 48bit address space, cut half */ | | 44 | #define __MD_VIRTUAL_SHIFT 47 /* 48bit address space, cut half */ |
45 | #define __MD_CANONICAL_BASE 0xFFFF800000000000 | | 45 | #define __MD_KERNMEM_BASE 0xFFFF800000000000 /* kern mem base address */ |
46 | | | 46 | |
47 | #define __MD_SHADOW_SIZE (1ULL << (__MD_VIRTUAL_SHIFT - KASAN_SHADOW_SCALE_SHIFT)) | | 47 | #define __MD_SHADOW_SIZE (1ULL << (__MD_VIRTUAL_SHIFT - KASAN_SHADOW_SCALE_SHIFT)) |
48 | #define KASAN_MD_SHADOW_START (VA_SIGN_NEG((L4_SLOT_KASAN * NBPD_L4))) | | 48 | #define KASAN_MD_SHADOW_START (VA_SIGN_NEG((L4_SLOT_KASAN * NBPD_L4))) |
49 | #define KASAN_MD_SHADOW_END (KASAN_MD_SHADOW_START + __MD_SHADOW_SIZE) | | 49 | #define KASAN_MD_SHADOW_END (KASAN_MD_SHADOW_START + __MD_SHADOW_SIZE) |
50 | | | 50 | |
51 | /* -------------------------------------------------------------------------- */ | | 51 | /* -------------------------------------------------------------------------- */ |
52 | | | 52 | |
53 | /* | | 53 | /* |
54 | * Early mapping, used to map just the stack at boot time. We rely on the fact | | 54 | * Early mapping, used to map just the stack at boot time. We rely on the fact |
55 | * that VA = PA + KERNBASE. | | 55 | * that VA = PA + KERNBASE. |
56 | */ | | 56 | */ |
57 | | | 57 | |
58 | static bool __md_early __read_mostly = true; | | 58 | static bool __md_early __read_mostly = true; |
| @@ -103,27 +103,27 @@ __md_early_shadow_map_page(vaddr_t va) | | | @@ -103,27 +103,27 @@ __md_early_shadow_map_page(vaddr_t va) |
103 | if (!pmap_valid_entry(pdir[pl1_pi(va)])) { | | 103 | if (!pmap_valid_entry(pdir[pl1_pi(va)])) { |
104 | pa = __md_early_palloc(); | | 104 | pa = __md_early_palloc(); |
105 | pdir[pl1_pi(va)] = pa | pteflags | pmap_pg_g; | | 105 | pdir[pl1_pi(va)] = pa | pteflags | pmap_pg_g; |
106 | } | | 106 | } |
107 | } | | 107 | } |
108 | | | 108 | |
109 | /* -------------------------------------------------------------------------- */ | | 109 | /* -------------------------------------------------------------------------- */ |
110 | | | 110 | |
111 | static inline int8_t * | | 111 | static inline int8_t * |
112 | kasan_md_addr_to_shad(const void *addr) | | 112 | kasan_md_addr_to_shad(const void *addr) |
113 | { | | 113 | { |
114 | vaddr_t va = (vaddr_t)addr; | | 114 | vaddr_t va = (vaddr_t)addr; |
115 | return (int8_t *)(KASAN_MD_SHADOW_START + | | 115 | return (int8_t *)(KASAN_MD_SHADOW_START + |
116 | ((va - __MD_CANONICAL_BASE) >> KASAN_SHADOW_SCALE_SHIFT)); | | 116 | ((va - __MD_KERNMEM_BASE) >> KASAN_SHADOW_SCALE_SHIFT)); |
117 | } | | 117 | } |
118 | | | 118 | |
119 | static inline bool | | 119 | static inline bool |
120 | kasan_md_unsupported(vaddr_t addr) | | 120 | kasan_md_unsupported(vaddr_t addr) |
121 | { | | 121 | { |
122 | return (addr >= (vaddr_t)PTE_BASE && | | 122 | return (addr >= (vaddr_t)PTE_BASE && |
123 | addr < ((vaddr_t)PTE_BASE + NBPD_L4)); | | 123 | addr < ((vaddr_t)PTE_BASE + NBPD_L4)); |
124 | } | | 124 | } |
125 | | | 125 | |
126 | static paddr_t | | 126 | static paddr_t |
127 | __md_palloc(void) | | 127 | __md_palloc(void) |
128 | { | | 128 | { |
129 | /* The page is zeroed. */ | | 129 | /* The page is zeroed. */ |