Skip to content

Commit

Permalink
libutils: malloc: use asan_memset_unchecked()
Browse files Browse the repository at this point in the history
The malloc implementation uses the new asan_memset_unchecked() function
internally instead of memset() to avoid unexpected asserts when the
address sanitizer is enabled.

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Sep 11, 2017
1 parent a1180bd commit 3f9995e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/libutils/isoc/bget.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void *bgetz(size)
rsize -= sizeof(struct bhead);
}
assert(rsize >= size);
V memset(buf, 0, (MemSize) rsize);
V memset_unchecked(buf, 0, (MemSize) rsize);
}
return ((void *) buf);
}
Expand Down Expand Up @@ -848,8 +848,8 @@ void brel(buf)
numdrel++; /* Number of direct releases */
#endif /* BufStats */
#ifdef FreeWipe
V memset((char *) buf, 0x55,
(MemSize) (bdh->tsize - sizeof(struct bdhead)));
V memset_unchecked((char *) buf, 0x55,
(MemSize) (bdh->tsize - sizeof(struct bdhead)));
#endif /* FreeWipe */
bs = bdh->tsize - sizeof(struct bdhead);
assert(relfcn != NULL);
Expand Down Expand Up @@ -936,8 +936,8 @@ void brel(buf)
bn = BFH(((char *) b) + b->bh.bsize);
}
#ifdef FreeWipe
V memset(((char *) b) + sizeof(struct bfhead), 0x55,
(MemSize) (b->bh.bsize - sizeof(struct bfhead)));
V memset_unchecked(((char *) b) + sizeof(struct bfhead), 0x55,
(MemSize) (b->bh.bsize - sizeof(struct bfhead)));
#endif
assert(bn->bh.bsize < 0);

Expand Down Expand Up @@ -1048,8 +1048,8 @@ void bpool(buf, len)
len -= sizeof(struct bhead);
b->bh.bsize = (bufsize) len;
#ifdef FreeWipe
V memset(((char *) b) + sizeof(struct bfhead), 0x55,
(MemSize) (len - sizeof(struct bfhead)));
V memset_unchecked(((char *) b) + sizeof(struct bfhead), 0x55,
(MemSize) (len - sizeof(struct bfhead)));
#endif
bn = BH(((char *) b) + len);
bn->prevfree = (bufsize) len;
Expand Down
20 changes: 16 additions & 4 deletions lib/libutils/isoc/bget_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@
#endif

#include <compiler.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <malloc.h>
#include <util.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <trace.h>
#include <util.h>

#if defined(__KERNEL__)
/* Compiling for TEE Core */
Expand Down Expand Up @@ -133,6 +134,11 @@ static void tag_asan_alloced(void *buf, size_t len)
asan_tag_access(buf, (uint8_t *)buf + len);
}

static void *memset_unchecked(void *s, int c, size_t n)
{
return asan_memset_unchecked(s, c, n);
}

#else /*__KERNEL__*/
/* Compiling for TA */
static uint32_t malloc_lock(void)
Expand All @@ -151,6 +157,12 @@ static void tag_asan_free(void *buf __unused, size_t len __unused)
static void tag_asan_alloced(void *buf __unused, size_t len __unused)
{
}

static void *memset_unchecked(void *s, int c, size_t n)
{
return memset(s, c, n);
}

#endif /*__KERNEL__*/

#include "bget.c" /* this is ugly, but this is bget */
Expand Down

0 comments on commit 3f9995e

Please sign in to comment.