Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions compiler-rt/lib/hwasan/hwasan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "hwasan.h"
#include "hwasan_allocator.h"
#include "hwasan_checks.h"
#include "hwasan_mapping.h"
#include "hwasan_platform_interceptors.h"
#include "hwasan_thread.h"
#include "hwasan_thread_list.h"
Expand Down Expand Up @@ -146,14 +147,6 @@ struct HWAsanInterceptorContext {
(void)(name); \
} while (false)

# define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \
do { \
(void)(ctx); \
(void)(block); \
(void)(c); \
(void)(size); \
} while (false)

# define COMMON_INTERCEPTOR_STRERROR() \
do { \
} while (false)
Expand All @@ -162,6 +155,9 @@ struct HWAsanInterceptorContext {

# define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED (!hwasan_inited)

# define COMMON_INTERCEPTOR_MEMSET_CHECK_IN_APP_MEM(p) \
MemIsApp(UntagAddr(reinterpret_cast<uptr>(p)))

// The main purpose of the mmap interceptor is to prevent the user from
// allocating on top of shadow pages.
//
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
#undef SANITIZER_INTERCEPT_STRCASECMP
#define SANITIZER_INTERCEPT_STRCASECMP 0

#undef SANITIZER_INTERCEPT_MEMSET
#define SANITIZER_INTERCEPT_MEMSET 0
// #undef SANITIZER_INTERCEPT_MEMSET
// #define SANITIZER_INTERCEPT_MEMSET 0

// #undef SANITIZER_INTERCEPT_MEMMOVE
// #define SANITIZER_INTERCEPT_MEMMOVE 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@
#define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 1
#endif // SANITIZER_APPLE

#ifndef COMMON_INTERCEPTOR_MEMSET_CHECK_IN_APP_MEM
#define COMMON_INTERCEPTOR_MEMSET_CHECK_IN_APP_MEM(p) (0)
#endif

#ifndef COMMON_INTERCEPTOR_MEMSET_IMPL
#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size) \
{ \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \
return internal_memset(dst, v, size); \
if (!COMMON_INTERCEPTOR_MEMSET_CHECK_IN_APP_MEM(dst)) \
return internal_memset(dst, v, size); \
COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); \
if (common_flags()->intercept_intrin) \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
Expand Down
32 changes: 32 additions & 0 deletions compiler-rt/test/hwasan/TestCases/memset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s

#include <sanitizer/hwasan_interface.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

__attribute__((no_sanitize("hwaddress"))) void
ForceCallInterceptor(void *p, int c, size_t size) {
memset(p, c, size) == nullptr;
}

int main(int argc, char **argv) {
__hwasan_enable_allocator_tagging();
char a[] = {static_cast<char>(argc), 2, 3, 4};
int size = sizeof(a);
char *volatile p = (char *)malloc(size);
free(p);
ForceCallInterceptor(p, 0, size);
return 0;
// CHECK: HWAddressSanitizer: tag-mismatch on address
// CHECK: WRITE of size 4
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset.cpp:[[@LINE-4]]
// CHECK: Cause: use-after-free
// CHECK: freed by thread
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset.cpp:[[@LINE-8]]
// CHECK: previously allocated by thread
// CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset.cpp:[[@LINE-11]]
}