Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
SWDEV-408660 - add needed address space checks to memory functions
Browse files Browse the repository at this point in the history
Change-Id: I7052efafb54fc6d9133dff220c06757e06f34ea0
(cherry picked from commit 085094d)
  • Loading branch information
b-sumner authored and searlmc1 committed Jun 30, 2023
1 parent 60d469f commit 78b5d10
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions asanrtl/src/memintrinsics.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,32 @@

NO_SANITIZE_ADDR
static void
check_memory_range_accessible(void* dest, const void* src,
uptr size, uptr pc) {
check_memory_range_accessible(const void* dst, const void* src, uptr size, uptr pc)
{
if (size == 0)
return;
uptr invalid_addr = 0;
uptr src_addr = (uptr)src;
invalid_addr = __asan_region_is_poisoned(src_addr, size);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, false, size, false)

if (!__ockl_is_private_addr(src) && !__ockl_is_local_addr(src)) {
uptr invalid_addr = __asan_region_is_poisoned((uptr)src, size);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, false, size, false)
}
}
uptr dest_addr = (uptr)dest;
invalid_addr = __asan_region_is_poisoned(dest_addr, size);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, true, size, false)

if (!__ockl_is_private_addr(dst) && !__ockl_is_local_addr(dst)) {
uptr invalid_addr = __asan_region_is_poisoned((uptr)dst, size);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, true, size, false)
}
}
}

USED
NO_INLINE
NO_SANITIZE_ADDR
void*
__asan_memcpy(void* to, const void* from, uptr size) {
__asan_memcpy(void* to, const void* from, uptr size)
{
uptr pc = GET_CALLER_PC();
check_memory_range_accessible(to, from, size, pc);
return __builtin_memcpy(to, from, size);
Expand All @@ -41,7 +45,8 @@ USED
NO_INLINE
NO_SANITIZE_ADDR
void*
__asan_memmove(void* to, const void* from, uptr size) {
__asan_memmove(void* to, const void* from, uptr size)
{
uptr pc = GET_CALLER_PC();
check_memory_range_accessible(to, from, size, pc);
return __builtin_memmove(to, from, size);
Expand All @@ -51,13 +56,17 @@ USED
NO_INLINE
NO_SANITIZE_ADDR
void*
__asan_memset(void* s, int c, uptr n) {
__asan_memset(void* s, int c, uptr n)
{
uptr pc = GET_CALLER_PC();
uptr src_addr = (uptr)s;
uptr invalid_addr = 0;
invalid_addr = __asan_region_is_poisoned(src_addr, n);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, true, n, false)

if (!__ockl_is_private_addr(s) && !__ockl_is_local_addr(s)) {
uptr invalid_addr = __asan_region_is_poisoned((uptr)s, n);
if (invalid_addr) {
REPORT_IMPL(pc, invalid_addr, true, n, false)
}
}

return __builtin_memset(s, c, n);
}

0 comments on commit 78b5d10

Please sign in to comment.