Skip to content

Commit

Permalink
core: asan: provide asan_memset_unchecked()
Browse files Browse the repository at this point in the history
Provides asan_memset_unchecked() which does a memset that isn't checked
against the tagging in the ASAN shadow area. If ASAN isn't enabled it's
replaced by a direct call to memset().

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Sep 11, 2017
1 parent 89c7db4 commit a1180bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions core/include/kernel/asan.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void asan_start(void);
void asan_tag_no_access(const void *begin, const void *end);
void asan_tag_access(const void *begin, const void *end);
void asan_tag_heap_free(const void *begin, const void *end);
void *asan_memset_unchecked(void *s, int c, size_t n);
#else
static inline void asan_tag_no_access(const void *begin __unused,
const void *end __unused)
Expand All @@ -58,6 +59,12 @@ static inline void asan_tag_heap_free(const void *begin __unused,
const void *end __unused)
{
}

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

#endif

#endif /*ASM*/
Expand Down
22 changes: 17 additions & 5 deletions core/kernel/asan.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void asan_tag_no_access(const void *begin, const void *end)
assert(va_is_well_aligned(end));
assert(va_range_inside_shadow(begin, end));

memset(va_to_shadow(begin), ASAN_DATA_RED_ZONE,
va_range_to_shadow_size(begin, end));
asan_memset_unchecked(va_to_shadow(begin), ASAN_DATA_RED_ZONE,
va_range_to_shadow_size(begin, end));
}

void asan_tag_access(const void *begin, const void *end)
Expand All @@ -128,7 +128,8 @@ void asan_tag_access(const void *begin, const void *end)
assert(va_range_inside_shadow(begin, end));
assert(va_is_well_aligned(begin));

memset(va_to_shadow(begin), 0, va_range_to_shadow_size(begin, end));
asan_memset_unchecked(va_to_shadow(begin), 0,
va_range_to_shadow_size(begin, end));
if (!va_is_well_aligned(end))
*va_to_shadow(end) = ASAN_BLOCK_SIZE - va_misalignment(end);
}
Expand All @@ -142,8 +143,19 @@ void asan_tag_heap_free(const void *begin, const void *end)
assert(va_is_well_aligned(begin));
assert(va_is_well_aligned(end));

memset(va_to_shadow(begin), ASAN_HEAP_RED_ZONE,
va_range_to_shadow_size(begin, end));
asan_memset_unchecked(va_to_shadow(begin), ASAN_HEAP_RED_ZONE,
va_range_to_shadow_size(begin, end));
}

void *asan_memset_unchecked(void *s, int c, size_t n)
{
uint8_t *b = s;
size_t m;

for (m = 0; m < n; m++)
b[m] = c;

return s;
}

void asan_start(void)
Expand Down

0 comments on commit a1180bd

Please sign in to comment.