1 #ifndef _included_clib_sanitizer_h
2 #define _included_clib_sanitizer_h
4 #ifdef CLIB_SANITIZE_ADDR
6 #include <sanitizer/asan_interface.h>
14 } clib_sanitizer_main_t;
16 extern clib_sanitizer_main_t sanitizer_main;
18 #define CLIB_NOSANITIZE_ADDR __attribute__((no_sanitize_address))
19 #define CLIB_MEM_POISON(a, s) ASAN_POISON_MEMORY_REGION((a), (s))
20 #define CLIB_MEM_UNPOISON(a, s) ASAN_UNPOISON_MEMORY_REGION((a), (s))
22 #define CLIB_MEM_OVERFLOW_MAX 64
25 sanitizer_unpoison__ (
u64 *restrict *shadow_ptr,
size_t *shadow_len,
26 const void *ptr,
size_t len)
31 __asan_get_shadow_mapping (&sanitizer_main.shadow_scale,
32 &sanitizer_main.shadow_offset);
34 scale = sanitizer_main.shadow_scale;
35 off = sanitizer_main.shadow_offset;
38 *shadow_len =
len >> scale;
39 ASSERT (*shadow_len <= CLIB_MEM_OVERFLOW_MAX);
44 sanitizer_unpoison_push__ (
u64 *restrict shadow,
const void *ptr,
size_t len)
46 u64 *restrict shadow_ptr;
50 sanitizer_unpoison__ (&shadow_ptr, &shadow_len, ptr,
len);
53 for (
i = 0;
i < shadow_len;
i++)
54 shadow[
i] = shadow_ptr[
i];
57 for (
i = 0;
i < shadow_len;
i++)
62 sanitizer_unpoison_pop__ (
const u64 *restrict shadow,
const void *ptr,
65 u64 *restrict shadow_ptr;
69 sanitizer_unpoison__ (&shadow_ptr, &shadow_len, ptr,
len);
72 for (
i = 0;
i < shadow_len;
i++)
75 shadow_ptr[
i] = shadow[
i];
79 #define CLIB_MEM_OVERFLOW(f, src, n) \
81 typeof (f) clib_mem_overflow_ret__; \
82 const void *clib_mem_overflow_src__ = (src); \
83 size_t clib_mem_overflow_n__ = (n); \
84 u64 clib_mem_overflow_shadow__[CLIB_MEM_OVERFLOW_MAX]; \
85 sanitizer_unpoison_push__ (clib_mem_overflow_shadow__, \
86 clib_mem_overflow_src__, \
87 clib_mem_overflow_n__); \
88 clib_mem_overflow_ret__ = f; \
89 sanitizer_unpoison_pop__ (clib_mem_overflow_shadow__, \
90 clib_mem_overflow_src__, \
91 clib_mem_overflow_n__); \
92 clib_mem_overflow_ret__; \
95 #define CLIB_MEM_OVERFLOW_LOAD(f, src) \
97 typeof(src) clib_mem_overflow_load_src__ = (src); \
98 CLIB_MEM_OVERFLOW(f(clib_mem_overflow_load_src__), clib_mem_overflow_load_src__, sizeof(typeof(f(clib_mem_overflow_load_src__)))); \
106 else if (newlen > oldlen)
112 #define CLIB_NOSANITIZE_ADDR
113 #define CLIB_MEM_POISON(a, s) (void)(a)
114 #define CLIB_MEM_UNPOISON(a, s) (void)(a)
115 #define CLIB_MEM_OVERFLOW(a, b, c) a
116 #define CLIB_MEM_OVERFLOW_LOAD(f, src) f(src)
117 #define CLIB_MEM_POISON_LEN(a, b, c)
128 #define CLIB_NOSANITIZE_PLUGIN_REG_SECTION CLIB_NOSANITIZE_ADDR
130 #define CLIB_NOSANITIZE_PLUGIN_REG_SECTION