[compiler-rt] ae6db86 - [hwasan] Use ErrorAction::Recover in interceptors (#74000)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 15:00:11 PST 2023
Author: Vitaly Buka
Date: 2023-12-04T15:00:08-08:00
New Revision: ae6db862a9ea0977e44127eb36e5d25e5673df04
URL: https://github.com/llvm/llvm-project/commit/ae6db862a9ea0977e44127eb36e5d25e5673df04
DIFF: https://github.com/llvm/llvm-project/commit/ae6db862a9ea0977e44127eb36e5d25e5673df04.diff
LOG: [hwasan] Use ErrorAction::Recover in interceptors (#74000)
Added:
compiler-rt/test/hwasan/TestCases/memset-recover.cpp
Modified:
compiler-rt/lib/hwasan/hwasan_interceptors.cpp
compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index 46c08f8268c09..96df4dd0c24d7 100644
--- a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
@@ -36,10 +36,10 @@ struct HWAsanInterceptorContext {
const char *interceptor_name;
};
-# define ACCESS_MEMORY_RANGE(offset, size, access) \
- do { \
- __hwasan::CheckAddressSized<ErrorAction::Abort, access>((uptr)offset, \
- size); \
+# define ACCESS_MEMORY_RANGE(offset, size, access) \
+ do { \
+ __hwasan::CheckAddressSized<ErrorAction::Recover, access>((uptr)offset, \
+ size); \
} while (0)
# define HWASAN_READ_RANGE(offset, size) \
@@ -74,9 +74,8 @@ struct HWAsanInterceptorContext {
# if HWASAN_WITH_INTERCEPTORS
-# define COMMON_SYSCALL_PRE_READ_RANGE(p, s) __hwasan_loadN((uptr)p, (uptr)s)
-# define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) \
- __hwasan_storeN((uptr)p, (uptr)s)
+# define COMMON_SYSCALL_PRE_READ_RANGE(p, s) HWASAN_READ_RANGE(p, s)
+# define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) HWASAN_WRITE_RANGE(p, s)
# define COMMON_SYSCALL_POST_READ_RANGE(p, s) \
do { \
(void)(p); \
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
index d7bc34ef324f5..154b698989935 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
@@ -1,5 +1,6 @@
-// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_hwasan -O3 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST
+// RUN: %clangxx_hwasan -O3 %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST
+// RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0:symbolize=0 %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST --check-prefixes=CHECK,RECOVER
// UNSUPPORTED: android
@@ -29,5 +30,7 @@ int main(int argc, char *argv[]) {
// CHECK: [[PTR]] is located 1 bytes before a 1000-byte region
free(buf);
+ fprintf(stderr, "RETURN_FROM_TEST\n");
+ // RECOVER: RETURN_FROM_TEST
return 0;
}
diff --git a/compiler-rt/test/hwasan/TestCases/memset-recover.cpp b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
new file mode 100644
index 0000000000000..093a0179347be
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
@@ -0,0 +1,32 @@
+// RUN: %clangxx_hwasan %s -o %t
+// RUN: %env_hwasan_opts=halt_on_error=0 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST --check-prefixes=CHECK,RECOVER
+// RUN: %env_hwasan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s --implicit-check-not=RETURN_FROM_TEST
+
+#include <sanitizer/hwasan_interface.h>
+#include <stdio.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);
+ void *volatile p2 = p;
+ for (int i = 0; p2 == p; p2 = __hwasan_tag_pointer(p, ++i)) {
+ }
+ ForceCallInterceptor(p2, 0, size);
+ free(p);
+ fprintf(stderr, "RETURN_FROM_TEST\n");
+ return 0;
+ // CHECK: HWAddressSanitizer: tag-mismatch on address
+ // CHECK: WRITE of size 4
+ // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memset-recover.cpp:[[@LINE-28]]
+ // RECOVER: RETURN_FROM_TEST
+}
More information about the llvm-commits
mailing list