[llvm] [lld] [libcxx] [flang] [clang] [lldb] [libc] [compiler-rt] [hwasan] Use ErrorAction::Recover in interceptors (PR #74000)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 2 16:43:23 PST 2023


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/74000

>From 672b71cc1003533460a82f06b7d24fbdc02ffd58 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 30 Nov 2023 14:44:07 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../lib/hwasan/hwasan_interceptors.cpp        |  8 ++---
 .../test/hwasan/TestCases/memset-recover.cpp  | 32 +++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)
 create mode 100644 compiler-rt/test/hwasan/TestCases/memset-recover.cpp

diff --git a/compiler-rt/lib/hwasan/hwasan_interceptors.cpp b/compiler-rt/lib/hwasan/hwasan_interceptors.cpp
index d9237cf9b8e3b..ee7166c942bbe 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 0000000000000..e29e7c412033e
--- /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
+}

>From 34550bbb8168aeae0e74b29d85ab92fdea50a9bd Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 30 Nov 2023 14:45:22 -0800
Subject: [PATCH 2/2] format

Created using spr 1.3.4
---
 compiler-rt/test/hwasan/TestCases/memset-recover.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/test/hwasan/TestCases/memset-recover.cpp b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
index e29e7c412033e..093a0179347be 100644
--- a/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
+++ b/compiler-rt/test/hwasan/TestCases/memset-recover.cpp
@@ -3,10 +3,10 @@
 // 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>
-#include <stdio.h>
 
 __attribute__((no_sanitize("hwaddress"))) void
 ForceCallInterceptor(void *p, int c, size_t size) {
@@ -23,7 +23,7 @@ int main(int argc, char **argv) {
   }
   ForceCallInterceptor(p2, 0, size);
   free(p);
-  fprintf(stderr,  "RETURN_FROM_TEST\n");
+  fprintf(stderr, "RETURN_FROM_TEST\n");
   return 0;
   // CHECK: HWAddressSanitizer: tag-mismatch on address
   // CHECK: WRITE of size 4



More information about the cfe-commits mailing list