summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/sanitizer.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-04-05 12:40:31 +0200
committerBeno�t Ganne <bganne@cisco.com>2022-04-05 14:46:15 +0000
commit79934e855fc58aefde498cd0564796cdd6ccbc59 (patch)
treedb3c5a33e1146915572160c33f2a0a8c9cbd18cd /src/vppinfra/sanitizer.h
parent0c740a6d8a6c11b1af4ce704220c2c46628f0a89 (diff)
vppinfra: refactor address sanitizer
Type: refactor Change-Id: I5ca142ec1557d5b5c3806b43553ad9d3b5ea1112 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/sanitizer.h')
-rw-r--r--src/vppinfra/sanitizer.h147
1 files changed, 0 insertions, 147 deletions
diff --git a/src/vppinfra/sanitizer.h b/src/vppinfra/sanitizer.h
deleted file mode 100644
index cf2da071225..00000000000
--- a/src/vppinfra/sanitizer.h
+++ /dev/null
@@ -1,147 +0,0 @@
-#ifndef _included_clib_sanitizer_h
-#define _included_clib_sanitizer_h
-
-#ifdef CLIB_SANITIZE_ADDR
-
-#include <sanitizer/asan_interface.h>
-#include <vppinfra/clib.h>
-#include <vppinfra/error_bootstrap.h>
-
-typedef struct
-{
- size_t shadow_scale;
- size_t shadow_offset;
-} clib_sanitizer_main_t;
-
-extern clib_sanitizer_main_t sanitizer_main;
-
-#define CLIB_NOSANITIZE_ADDR __attribute__((no_sanitize_address))
-#define CLIB_MEM_POISON(a, s) ASAN_POISON_MEMORY_REGION((a), (s))
-#define CLIB_MEM_UNPOISON(a, s) ASAN_UNPOISON_MEMORY_REGION((a), (s))
-
-#define CLIB_MEM_OVERFLOW_MAX 64
-
-static_always_inline void
-sanitizer_unpoison__ (u64 *restrict *shadow_ptr, size_t *shadow_len,
- const void *ptr, size_t len)
-{
- size_t scale, off;
-
- if (PREDICT_FALSE (~0 == sanitizer_main.shadow_scale))
- __asan_get_shadow_mapping (&sanitizer_main.shadow_scale,
- &sanitizer_main.shadow_offset);
-
- scale = sanitizer_main.shadow_scale;
- off = sanitizer_main.shadow_offset;
-
- /* compute the shadow address and length */
- *shadow_len = len >> scale;
- ASSERT (*shadow_len <= CLIB_MEM_OVERFLOW_MAX);
- *shadow_ptr = (void *) (((clib_address_t) ptr >> scale) + off);
-}
-
-static_always_inline CLIB_NOSANITIZE_ADDR void
-sanitizer_unpoison_push__ (u64 *restrict shadow, const void *ptr, size_t len)
-{
- u64 *restrict shadow_ptr;
- size_t shadow_len;
- int i;
-
- sanitizer_unpoison__ (&shadow_ptr, &shadow_len, ptr, len);
-
- /* save the shadow area */
- for (i = 0; i < shadow_len; i++)
- shadow[i] = shadow_ptr[i];
-
- /* unpoison */
- for (i = 0; i < shadow_len; i++)
- shadow_ptr[i] = 0;
-}
-
-static_always_inline CLIB_NOSANITIZE_ADDR void
-sanitizer_unpoison_pop__ (const u64 *restrict shadow, const void *ptr,
- size_t len)
-{
- u64 *restrict shadow_ptr;
- size_t shadow_len;
- int i;
-
- sanitizer_unpoison__ (&shadow_ptr, &shadow_len, ptr, len);
-
- /* restore the shadow area */
- for (i = 0; i < shadow_len; i++)
- {
- ASSERT (0 == shadow_ptr[i]);
- shadow_ptr[i] = shadow[i];
- }
-}
-
-#define CLIB_MEM_OVERFLOW_PUSH(src, n) \
- do \
- { \
- const void *clib_mem_overflow_src__ = (src); \
- size_t clib_mem_overflow_n__ = (n); \
- u64 clib_mem_overflow_shadow__; \
- sanitizer_unpoison_push__ (&clib_mem_overflow_shadow__, \
- clib_mem_overflow_src__, \
- clib_mem_overflow_n__)
-
-#define CLIB_MEM_OVERFLOW_POP() \
- sanitizer_unpoison_pop__ (&clib_mem_overflow_shadow__, \
- clib_mem_overflow_src__, clib_mem_overflow_n__); \
- } \
- while (0)
-
-#define CLIB_MEM_OVERFLOW_LOAD(src) \
- ({ \
- typeof (*(src)) *clib_mem_overflow_load_src__ = (src), \
- clib_mem_overflow_load_ret__; \
- CLIB_MEM_OVERFLOW_PUSH (clib_mem_overflow_load_src__, \
- sizeof (*clib_mem_overflow_load_src__)); \
- clib_mem_overflow_load_ret__ = *clib_mem_overflow_load_src__; \
- CLIB_MEM_OVERFLOW_POP (); \
- clib_mem_overflow_load_ret__; \
- })
-
-static_always_inline void
-CLIB_MEM_POISON_LEN (void *src, size_t oldlen, size_t newlen)
-{
- if (oldlen > newlen)
- CLIB_MEM_POISON (src + newlen, oldlen - newlen);
- else if (newlen > oldlen)
- CLIB_MEM_UNPOISON (src + oldlen, newlen - oldlen);
-}
-
-#else /* CLIB_SANITIZE_ADDR */
-
-#define CLIB_NOSANITIZE_ADDR
-#define CLIB_MEM_POISON(a, s) (void)(a)
-#define CLIB_MEM_UNPOISON(a, s) (void)(a)
-#define CLIB_MEM_OVERFLOW_PUSH(a, b) (void) (a)
-#define CLIB_MEM_OVERFLOW_POP()
-#define CLIB_MEM_OVERFLOW_LOAD(src) (*(src))
-#define CLIB_MEM_POISON_LEN(a, b, c)
-
-#endif /* CLIB_SANITIZE_ADDR */
-
-/*
- * clang tends to force alignment of all sections when compiling for address
- * sanitizer. This confuse VPP plugin infra, prevent clang to do that
- * On the contrary, GCC does not support this kind of attribute on sections
- * sigh.
- */
-#ifdef __clang__
-#define CLIB_NOSANITIZE_PLUGIN_REG_SECTION CLIB_NOSANITIZE_ADDR
-#else
-#define CLIB_NOSANITIZE_PLUGIN_REG_SECTION
-#endif
-
-#endif /* _included_clib_sanitizer_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */