summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/CMakeLists.txt2
-rw-r--r--src/vppinfra/clib.h15
-rw-r--r--src/vppinfra/dlmalloc.c61
-rw-r--r--src/vppinfra/elf.c2
-rw-r--r--src/vppinfra/linux/mem.c4
-rw-r--r--src/vppinfra/mem.h22
-rw-r--r--src/vppinfra/mem_bulk.c10
-rw-r--r--src/vppinfra/mem_dlmalloc.c15
-rw-r--r--src/vppinfra/pool.h12
-rw-r--r--src/vppinfra/sanitizer.c7
-rw-r--r--src/vppinfra/sanitizer.h147
-rw-r--r--src/vppinfra/vec.c6
-rw-r--r--src/vppinfra/vec_bootstrap.h6
13 files changed, 92 insertions, 217 deletions
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 2061e4fdc4a..8f7129aa488 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -78,7 +78,6 @@ set(VPPINFRA_SRCS
random.c
random_isaac.c
rbtree.c
- sanitizer.c
serialize.c
socket.c
std-formats.c
@@ -103,7 +102,6 @@ set(VPPINFRA_SRCS
)
set(VPPINFRA_HEADERS
- sanitizer.h
bihash_12_4.h
bihash_16_8.h
bihash_24_8.h
diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h
index 8d1674945dd..2db611d969b 100644
--- a/src/vppinfra/clib.h
+++ b/src/vppinfra/clib.h
@@ -95,6 +95,15 @@
/* Make a string from the macro's argument */
#define CLIB_STRING_MACRO(x) #x
+/* sanitizers */
+#ifdef __has_feature
+#if __has_feature(address_sanitizer)
+#define CLIB_SANITIZE_ADDR 1
+#endif
+#elif defined(__SANITIZE_ADDRESS__)
+#define CLIB_SANITIZE_ADDR 1
+#endif
+
#define __clib_unused __attribute__ ((unused))
#define __clib_weak __attribute__ ((weak))
#define __clib_packed __attribute__ ((packed))
@@ -117,6 +126,12 @@
__attribute__ ((optimize ("no-optimize-sibling-calls")))
#endif
+#ifdef CLIB_SANITIZE_ADDR
+#define __clib_nosanitize_addr __attribute__ ((no_sanitize_address))
+#else
+#define __clib_nosanitize_addr
+#endif
+
#define never_inline __attribute__ ((__noinline__))
#if CLIB_DEBUG > 0
diff --git a/src/vppinfra/dlmalloc.c b/src/vppinfra/dlmalloc.c
index 03e7d874032..143db33c4b4 100644
--- a/src/vppinfra/dlmalloc.c
+++ b/src/vppinfra/dlmalloc.c
@@ -6,7 +6,6 @@
*/
#include <vppinfra/dlmalloc.h>
-#include <vppinfra/sanitizer.h>
/*------------------------------ internal #includes ---------------------- */
@@ -460,7 +459,7 @@ static FORCEINLINE void x86_clear_lock(int* sl) {
#if !defined(USE_RECURSIVE_LOCKS) || USE_RECURSIVE_LOCKS == 0
/* Plain spin locks use single word (embedded in malloc_states) */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static int spin_acquire_lock(int *sl) {
int spins = 0;
while (*(volatile int *)sl != 0 || CAS_LOCK(sl)) {
@@ -1286,7 +1285,7 @@ static struct malloc_state _gm_;
((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
/* Return segment holding given address */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static msegmentptr segment_holding(mstate m, char* addr) {
msegmentptr sp = &m->seg;
for (;;) {
@@ -1298,7 +1297,7 @@ static msegmentptr segment_holding(mstate m, char* addr) {
}
/* Return true if segment contains a segment link */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static int has_segment_link(mstate m, msegmentptr ss) {
msegmentptr sp = &m->seg;
for (;;) {
@@ -1616,7 +1615,7 @@ static size_t traverse_and_check(mstate m);
#if (FOOTERS && !INSECURE)
/* Check if (alleged) mstate m has expected magic field */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static inline int
ok_magic (const mstate m)
{
@@ -2083,7 +2082,7 @@ static void do_check_malloc_state(mstate m) {
/* ----------------------------- statistics ------------------------------ */
#if !NO_MALLINFO
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static struct dlmallinfo internal_mallinfo(mstate m) {
struct dlmallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
ensure_initialization();
@@ -2493,7 +2492,7 @@ static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) {
/* -------------------------- mspace management -------------------------- */
/* Initialize top chunk and its size */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void init_top(mstate m, mchunkptr p, size_t psize) {
/* Ensure alignment */
size_t offset = align_offset(chunk2mem(p));
@@ -2538,7 +2537,7 @@ static void reset_on_error(mstate m) {
#endif /* PROCEED_ON_ERROR */
/* Allocate chunk and prepend remainder with chunk in successor base. */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void* prepend_alloc(mstate m, char* newbase, char* oldbase,
size_t nb) {
mchunkptr p = align_as_chunk(newbase);
@@ -2581,7 +2580,7 @@ static void* prepend_alloc(mstate m, char* newbase, char* oldbase,
}
/* Add a segment to hold a new noncontiguous region */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) {
/* Determine locations and sizes of segment, fenceposts, old top */
char* old_top = (char*)m->top;
@@ -2637,7 +2636,7 @@ static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) {
/* -------------------------- System allocation -------------------------- */
/* Get memory from system using MORECORE or MMAP */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void* sys_alloc(mstate m, size_t nb) {
char* tbase = CMFAIL;
size_t tsize = 0;
@@ -2852,7 +2851,7 @@ static void* sys_alloc(mstate m, size_t nb) {
/* ----------------------- system deallocation -------------------------- */
/* Unmap and unlink any mmapped segments that don't contain used chunks */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static size_t release_unused_segments(mstate m) {
size_t released = 0;
int nsegs = 0;
@@ -2900,7 +2899,7 @@ static size_t release_unused_segments(mstate m) {
return released;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static int sys_trim(mstate m, size_t pad) {
size_t released = 0;
ensure_initialization();
@@ -2969,7 +2968,7 @@ static int sys_trim(mstate m, size_t pad) {
/* Consolidate and bin a chunk. Differs from exported versions
of free mainly in that the chunk need not be marked as inuse.
*/
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void dispose_chunk(mstate m, mchunkptr p, size_t psize) {
mchunkptr next = chunk_plus_offset(p, psize);
if (!pinuse(p)) {
@@ -3041,7 +3040,7 @@ static void dispose_chunk(mstate m, mchunkptr p, size_t psize) {
/* ---------------------------- malloc --------------------------- */
/* allocate a large request from the best fitting chunk in a treebin */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void* tmalloc_large(mstate m, size_t nb) {
tchunkptr v = 0;
size_t rsize = -nb; /* Unsigned negation */
@@ -3113,7 +3112,7 @@ static void* tmalloc_large(mstate m, size_t nb) {
}
/* allocate a small request from the best fitting chunk in a treebin */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void* tmalloc_small(mstate m, size_t nb) {
tchunkptr t, v;
size_t rsize;
@@ -3420,7 +3419,7 @@ void* dlcalloc(size_t n_elements, size_t elem_size) {
/* ------------ Internal support for realloc, memalign, etc -------------- */
/* Try to realloc; only in-place unless can_move true */
-static CLIB_NOSANITIZE_ADDR mchunkptr try_realloc_chunk(mstate m, mchunkptr p, size_t nb,
+static __clib_nosanitize_addr mchunkptr try_realloc_chunk(mstate m, mchunkptr p, size_t nb,
int can_move) {
mchunkptr newp = 0;
size_t oldsize = chunksize(p);
@@ -3499,7 +3498,7 @@ static CLIB_NOSANITIZE_ADDR mchunkptr try_realloc_chunk(mstate m, mchunkptr p, s
return newp;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
static void* internal_memalign(mstate m, size_t alignment, size_t bytes) {
void* mem = 0;
if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */
@@ -4082,7 +4081,7 @@ int mspace_track_large_chunks(mspace msp, int enable) {
return ret;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
size_t destroy_mspace(mspace msp) {
size_t freed = 0;
mstate ms = (mstate)msp;
@@ -4118,7 +4117,7 @@ void mspace_get_address_and_size (mspace msp, char **addrp, size_t *sizep)
*sizep = this_seg->size;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
int mspace_is_heap_object (mspace msp, void *p)
{
msegment *this_seg;
@@ -4144,7 +4143,7 @@ int mspace_is_heap_object (mspace msp, void *p)
return 0;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void *mspace_least_addr (mspace msp)
{
mstate ms = (mstate) msp;
@@ -4158,7 +4157,7 @@ void mspace_disable_expand (mspace msp)
disable_expand (ms);
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
int mspace_enable_disable_trace (mspace msp, int enable)
{
mstate ms = (mstate)msp;
@@ -4175,7 +4174,7 @@ int mspace_enable_disable_trace (mspace msp, int enable)
return (was_enabled);
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
int mspace_is_traced (mspace msp)
{
mstate ms = (mstate)msp;
@@ -4185,7 +4184,7 @@ int mspace_is_traced (mspace msp)
return 0;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void* mspace_get_aligned (mspace msp,
unsigned long n_user_data_bytes,
unsigned long align,
@@ -4265,7 +4264,7 @@ void* mspace_get_aligned (mspace msp,
return (void *) searchp;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void mspace_put (mspace msp, void *p_arg)
{
char *object_header;
@@ -4315,7 +4314,7 @@ void mspace_put_no_offset (mspace msp, void *p_arg)
mspace_free (msp, p_arg);
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
size_t mspace_usable_size_with_delta (const void *p)
{
size_t usable_size;
@@ -4341,7 +4340,7 @@ size_t mspace_usable_size_with_delta (const void *p)
versions. This is not so nice but better than the alternatives.
*/
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void* mspace_malloc(mspace msp, size_t bytes) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
@@ -4456,7 +4455,7 @@ void* mspace_malloc(mspace msp, size_t bytes) {
return 0;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void mspace_free(mspace msp, void* mem) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
@@ -4623,7 +4622,7 @@ void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) {
return mem;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void* mspace_realloc_in_place(mspace msp, void* oldmem, size_t bytes) {
void* mem = 0;
if (oldmem != 0) {
@@ -4656,7 +4655,7 @@ void* mspace_realloc_in_place(mspace msp, void* oldmem, size_t bytes) {
return mem;
}
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
@@ -4796,7 +4795,7 @@ size_t mspace_set_footprint_limit(mspace msp, size_t bytes) {
}
#if !NO_MALLINFO
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
struct dlmallinfo mspace_mallinfo(mspace msp) {
mstate ms = (mstate)msp;
if (!ok_magic(ms)) {
@@ -4806,7 +4805,7 @@ struct dlmallinfo mspace_mallinfo(mspace msp) {
}
#endif /* NO_MALLINFO */
-CLIB_NOSANITIZE_ADDR
+__clib_nosanitize_addr
size_t mspace_usable_size(const void* mem) {
if (mem != 0) {
mchunkptr p = mem2chunk(mem);
diff --git a/src/vppinfra/elf.c b/src/vppinfra/elf.c
index d11fd7e99a9..af0b2b8cb6f 100644
--- a/src/vppinfra/elf.c
+++ b/src/vppinfra/elf.c
@@ -1357,7 +1357,7 @@ elf_read_file (elf_main_t * em, char *file_name)
goto done;
}
- CLIB_MEM_UNPOISON (data, mmap_length);
+ clib_mem_unpoison (data, mmap_length);
em->file_name = file_name;
diff --git a/src/vppinfra/linux/mem.c b/src/vppinfra/linux/mem.c
index 9cf598d3c6f..4365281ce8c 100644
--- a/src/vppinfra/linux/mem.c
+++ b/src/vppinfra/linux/mem.c
@@ -455,7 +455,7 @@ clib_mem_vm_map_internal (void *base, clib_mem_page_sz_t log2_page_sz,
else
mm->first_map = hdr;
- CLIB_MEM_UNPOISON (hdr, sys_page_sz);
+ clib_mem_unpoison (hdr, sys_page_sz);
hdr->next = 0;
hdr->prev = mm->last_map;
snprintf (hdr->name, CLIB_VM_MAP_HDR_NAME_MAX_LEN - 1, "%s", (char *) name);
@@ -470,7 +470,7 @@ clib_mem_vm_map_internal (void *base, clib_mem_page_sz_t log2_page_sz,
map_unlock ();
- CLIB_MEM_UNPOISON (base, size);
+ clib_mem_unpoison (base, size);
return base;
}
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index e33ab37e877..75015d59a4a 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -47,7 +47,9 @@
#include <vppinfra/os.h>
#include <vppinfra/string.h> /* memcpy, clib_memset */
-#include <vppinfra/sanitizer.h>
+#ifdef CLIB_SANITIZE_ADDR
+#include <sanitizer/asan_interface.h>
+#endif
#define CLIB_MAX_MHEAPS 256
#define CLIB_MAX_NUMAS 16
@@ -163,6 +165,22 @@ extern clib_mem_main_t clib_mem_main;
/* Unspecified NUMA socket */
#define VEC_NUMA_UNSPECIFIED (0xFF)
+static_always_inline void
+clib_mem_poison (const void volatile *p, uword s)
+{
+#ifdef CLIB_SANITIZE_ADDR
+ ASAN_POISON_MEMORY_REGION (p, s);
+#endif
+}
+
+static_always_inline void
+clib_mem_unpoison (const void volatile *p, uword s)
+{
+#ifdef CLIB_SANITIZE_ADDR
+ ASAN_UNPOISON_MEMORY_REGION (p, s);
+#endif
+}
+
always_inline clib_mem_heap_t *
clib_mem_get_per_cpu_heap (void)
{
@@ -336,7 +354,7 @@ clib_mem_vm_alloc (uword size)
if (mmap_addr == (void *) -1)
mmap_addr = 0;
else
- CLIB_MEM_UNPOISON (mmap_addr, size);
+ clib_mem_unpoison (mmap_addr, size);
return mmap_addr;
}
diff --git a/src/vppinfra/mem_bulk.c b/src/vppinfra/mem_bulk.c
index ba8b2e94909..4dd6a168217 100644
--- a/src/vppinfra/mem_bulk.c
+++ b/src/vppinfra/mem_bulk.c
@@ -66,7 +66,7 @@ clib_mem_bulk_init (u32 elt_sz, u32 align, u32 min_elts_per_chunk)
if (min_elts_per_chunk == 0)
min_elts_per_chunk = CLIB_MEM_BULK_DEFAULT_MIN_ELTS_PER_CHUNK;
- CLIB_MEM_UNPOISON (b, sizeof (clib_mem_bulk_t));
+ clib_mem_unpoison (b, sizeof (clib_mem_bulk_t));
clib_memset (b, 0, sizeof (clib_mem_bulk_t));
b->mspace = heap->mspace;
b->align = align;
@@ -92,7 +92,7 @@ again:
while (c)
{
next = c->next;
- CLIB_MEM_POISON (c, bulk_chunk_size (b));
+ clib_mem_poison (c, bulk_chunk_size (b));
mspace_free (ms, c);
c = next;
}
@@ -104,7 +104,7 @@ again:
goto again;
}
- CLIB_MEM_POISON (b, sizeof (clib_mem_bulk_t));
+ clib_mem_poison (b, sizeof (clib_mem_bulk_t));
mspace_free (ms, b);
}
@@ -148,7 +148,7 @@ clib_mem_bulk_alloc (clib_mem_bulk_handle_t h)
{
u32 i, sz = bulk_chunk_size (b);
c = mspace_memalign (b->mspace, b->chunk_align, sz);
- CLIB_MEM_UNPOISON (c, sz);
+ clib_mem_unpoison (c, sz);
clib_memset (c, 0, sizeof (clib_mem_bulk_chunk_hdr_t));
b->avail_chunks = c;
c->n_free = b->elts_per_chunk;
@@ -192,7 +192,7 @@ clib_mem_bulk_free (clib_mem_bulk_handle_t h, void *p)
{
/* chunk is empty - give it back */
remove_from_chunk_list (&b->avail_chunks, c);
- CLIB_MEM_POISON (c, bulk_chunk_size (b));
+ clib_mem_poison (c, bulk_chunk_size (b));
mspace_free (b->mspace, c);
return;
}
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index fdde720bc73..4150fbe8b4b 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -19,7 +19,6 @@
#include <vppinfra/lock.h>
#include <vppinfra/hash.h>
#include <vppinfra/elf_clib.h>
-#include <vppinfra/sanitizer.h>
typedef struct
{
@@ -235,7 +234,7 @@ clib_mem_create_heap_internal (void *base, uword size,
mspace_disable_expand (h->mspace);
- CLIB_MEM_POISON (mspace_least_addr (h->mspace),
+ clib_mem_poison (mspace_least_addr (h->mspace),
mspace_footprint (h->mspace));
return h;
@@ -619,7 +618,7 @@ clib_mem_heap_alloc_inline (void *heap, uword size, uword align,
if (PREDICT_FALSE (h->flags & CLIB_MEM_HEAP_F_TRACED))
mheap_get_trace (pointer_to_uword (p), clib_mem_size (p));
- CLIB_MEM_UNPOISON (p, size);
+ clib_mem_unpoison (p, size);
return p;
}
@@ -699,16 +698,16 @@ clib_mem_heap_realloc_aligned (void *heap, void *p, uword new_size,
if (p && pointer_is_aligned (p, align) &&
mspace_realloc_in_place (h->mspace, p, new_size))
{
- CLIB_MEM_UNPOISON (p, new_size);
+ clib_mem_unpoison (p, new_size);
}
else
{
new = clib_mem_heap_alloc_inline (h, new_size, align, 1);
- CLIB_MEM_UNPOISON (new, new_size);
+ clib_mem_unpoison (new, new_size);
if (old_alloc_size)
{
- CLIB_MEM_UNPOISON (p, old_alloc_size);
+ clib_mem_unpoison (p, old_alloc_size);
clib_memcpy_fast (new, p, clib_min (new_size, old_alloc_size));
clib_mem_heap_free (h, p);
}
@@ -760,7 +759,7 @@ clib_mem_heap_free (void *heap, void *p)
if (PREDICT_FALSE (h->flags & CLIB_MEM_HEAP_F_TRACED))
mheap_put_trace (pointer_to_uword (p), size);
- CLIB_MEM_POISON (p, clib_mem_size (p));
+ clib_mem_poison (p, clib_mem_size (p));
mspace_free (h->mspace, p);
}
@@ -781,7 +780,7 @@ __clib_export void
clib_mem_free_s (void *p)
{
uword size = clib_mem_size (p);
- CLIB_MEM_UNPOISON (p, size);
+ clib_mem_unpoison (p, size);
memset_s_inline (p, size, 0, size);
clib_mem_free (p);
}
diff --git a/src/vppinfra/pool.h b/src/vppinfra/pool.h
index 9f9194f59e2..8330d64b0bd 100644
--- a/src/vppinfra/pool.h
+++ b/src/vppinfra/pool.h
@@ -185,7 +185,7 @@ _pool_get (void **pp, void **ep, uword align, int zero, uword elt_sz)
ph->free_bitmap =
clib_bitmap_andnoti_notrim (ph->free_bitmap, index);
vec_set_len (ph->free_indices, n_free - 1);
- CLIB_MEM_UNPOISON (e, elt_sz);
+ clib_mem_unpoison (e, elt_sz);
goto done;
}
@@ -299,7 +299,7 @@ _pool_put_index (void *p, uword index, uword elt_sz)
else
vec_add1 (ph->free_indices, index);
- CLIB_MEM_POISON (p + index * elt_sz, elt_sz);
+ clib_mem_poison (p + index * elt_sz, elt_sz);
}
#define pool_put_index(P, I) _pool_put_index ((void *) (P), I, _vec_elt_sz (P))
@@ -322,7 +322,7 @@ _pool_alloc (void **pp, uword n_elts, uword align, void *heap, uword elt_sz)
pp[0] = _vec_realloc_inline (pp[0], len + n_elts, elt_sz,
sizeof (pool_header_t), align, heap);
_vec_set_len (pp[0], len, elt_sz);
- CLIB_MEM_POISON (pp[0] + len * elt_sz, n_elts * elt_sz);
+ clib_mem_poison (pp[0] + len * elt_sz, n_elts * elt_sz);
ph = pool_header (pp[0]);
vec_resize (ph->free_indices, n_elts);
@@ -358,7 +358,7 @@ _pool_dup (void *p, uword align, uword elt_sz)
{
u32 *fi;
vec_foreach (fi, ph->free_indices)
- CLIB_MEM_UNPOISON (p + elt_sz * fi[0], elt_sz);
+ clib_mem_unpoison (p + elt_sz * fi[0], elt_sz);
clib_memcpy_fast (n, p, len * elt_sz);
@@ -368,8 +368,8 @@ _pool_dup (void *p, uword align, uword elt_sz)
vec_foreach (fi, ph->free_indices)
{
uword offset = elt_sz * fi[0];
- CLIB_MEM_POISON (p + offset, elt_sz);
- CLIB_MEM_POISON (n + offset, elt_sz);
+ clib_mem_poison (p + offset, elt_sz);
+ clib_mem_poison (n + offset, elt_sz);
}
}
diff --git a/src/vppinfra/sanitizer.c b/src/vppinfra/sanitizer.c
deleted file mode 100644
index fab1cdca136..00000000000
--- a/src/vppinfra/sanitizer.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifdef CLIB_SANITIZE_ADDR
-
-#include <vppinfra/sanitizer.h>
-
-__clib_export clib_sanitizer_main_t sanitizer_main = { .shadow_scale = ~0 };
-
-#endif /* CLIB_SANITIZE_ADDR */
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:
- */
diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c
index 8bd0ec01f42..4dc8f18ce24 100644
--- a/src/vppinfra/vec.c
+++ b/src/vppinfra/vec.c
@@ -55,7 +55,7 @@ _vec_realloc (void *v, uword n_elts, uword elt_sz, uword hdr_sz, uword align,
v = p + data_offset;
}
- CLIB_MEM_UNPOISON (p, alloc_size);
+ clib_mem_unpoison (p, alloc_size);
clib_memset_u8 (p + old_data_size, 0, alloc_size - old_data_size);
}
else
@@ -68,7 +68,7 @@ _vec_realloc (void *v, uword n_elts, uword elt_sz, uword hdr_sz, uword align,
new_data_size = data_offset + n_data_bytes;
p = clib_mem_heap_alloc_aligned (heap, new_data_size, align);
alloc_size = clib_mem_size (p);
- CLIB_MEM_UNPOISON (p, alloc_size);
+ clib_mem_unpoison (p, alloc_size);
clib_memset_u8 (p, 0, alloc_size);
v = p + data_offset;
_vec_find (v)->hdr_size = data_offset / VEC_MIN_ALIGN;
@@ -82,7 +82,7 @@ _vec_realloc (void *v, uword n_elts, uword elt_sz, uword hdr_sz, uword align,
_vec_find (v)->default_heap = 1;
}
- CLIB_MEM_POISON (p + new_data_size, alloc_size - new_data_size);
+ clib_mem_poison (p + new_data_size, alloc_size - new_data_size);
_vec_find (v)->len = n_elts;
return v;
}
diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h
index 0054802e8c1..a94c1a19ba7 100644
--- a/src/vppinfra/vec_bootstrap.h
+++ b/src/vppinfra/vec_bootstrap.h
@@ -85,7 +85,7 @@ always_inline uword __vec_elt_sz (uword elt_sz, int is_void);
#define _vec_elt_sz(V) __vec_elt_sz (sizeof ((V)[0]), _vec_is_void (V))
#define _vec_align(V, A) __vec_align (__alignof__((V)[0]), A)
-always_inline CLIB_NOSANITIZE_ADDR uword
+always_inline __clib_nosanitize_addr uword
vec_get_header_size (void *v)
{
uword header_size = _vec_find (v)->hdr_size * VEC_MIN_ALIGN;
@@ -176,9 +176,9 @@ _vec_set_len (void *v, uword len, uword elt_sz)
uword old_len = _vec_len (v);
if (len > old_len)
- CLIB_MEM_UNPOISON (v + old_len * elt_sz, (len - old_len) * elt_sz);
+ clib_mem_unpoison (v + old_len * elt_sz, (len - old_len) * elt_sz);
else if (len > old_len)
- CLIB_MEM_POISON (v + len * elt_sz, (old_len - len) * elt_sz);
+ clib_mem_poison (v + len * elt_sz, (old_len - len) * elt_sz);
_vec_find (v)->len = len;
}