[compiler-rt] [hwasan] Use ErrorAction::Recover in interceptors (PR #74000)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 14:44:57 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/74000.diff
2 Files Affected:
- (modified) compiler-rt/lib/hwasan/hwasan_interceptors.cpp (+4-4)
- (added) compiler-rt/test/hwasan/TestCases/memset-recover.cpp (+32)
``````````diff
diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index d9237cf9b8e3bf9..ee7166c942bbe9a 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(ctx, offset, size, access) \
- do { \
- __hwasan::CheckAddressSized<ErrorAction::Abort, access>((uptr)offset, \
- size); \
+# define ACCESS_MEMORY_RANGE(ctx, offset, size, access) \
+ do { \
+ __hwasan::CheckAddressSized<ErrorAction::Recover, access>((uptr)offset, \
+ size); \
} while (0)
# define HWASAN_READ_RANGE(ctx, offset, size) \
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 000000000000000..e29e7c412033e2b
--- /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 <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/74000
More information about the llvm-commits
mailing list