[compiler-rt] ddf4a9c - [test][HWASAN] Force interceptors tests for memcmp and bcmp call interceptor (#71215)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 3 13:55:56 PDT 2023


Author: Kirill Stoimenov
Date: 2023-11-03T13:55:52-07:00
New Revision: ddf4a9ce636084b45b39634cabe4da25b73f0e0a

URL: https://github.com/llvm/llvm-project/commit/ddf4a9ce636084b45b39634cabe4da25b73f0e0a
DIFF: https://github.com/llvm/llvm-project/commit/ddf4a9ce636084b45b39634cabe4da25b73f0e0a.diff

LOG: [test][HWASAN] Force interceptors tests for memcmp and bcmp call interceptor (#71215)

Added: 
    

Modified: 
    compiler-rt/test/hwasan/TestCases/bcmp.cpp
    compiler-rt/test/hwasan/TestCases/memcmp.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/hwasan/TestCases/bcmp.cpp b/compiler-rt/test/hwasan/TestCases/bcmp.cpp
index a83147b0f320528..9b21bba56b1beea 100644
--- a/compiler-rt/test/hwasan/TestCases/bcmp.cpp
+++ b/compiler-rt/test/hwasan/TestCases/bcmp.cpp
@@ -4,11 +4,17 @@
 // RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
 // REQUIRES: !android
 
+#include <assert.h>
 #include <sanitizer/hwasan_interface.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+__attribute__((no_sanitize("hwaddress"))) void
+ForceCallInterceptor(void *p, const void *a, size_t size) {
+  assert(bcmp(p, a, size) == 0);
+}
+
 int main(int argc, char **argv) {
   __hwasan_enable_allocator_tagging();
   char a[] = {static_cast<char>(argc), 2, 3, 4};
@@ -16,13 +22,14 @@ int main(int argc, char **argv) {
   char *p = (char *)malloc(size);
   memcpy(p, a, size);
   free(p);
-  return bcmp(p, a, size);
+  ForceCallInterceptor(p, a, size);
+  return 0;
   // CHECK: HWAddressSanitizer: tag-mismatch on address
   // CHECK: READ of size 4
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-3]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-4]]
   // CHECK: Cause: use-after-free
   // CHECK: freed by thread
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-7]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-8]]
   // CHECK: previously allocated by thread
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-11]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-12]]
 }

diff  --git a/compiler-rt/test/hwasan/TestCases/memcmp.cpp b/compiler-rt/test/hwasan/TestCases/memcmp.cpp
index 5f8a93f62a44a1d..31915527c27fdd4 100644
--- a/compiler-rt/test/hwasan/TestCases/memcmp.cpp
+++ b/compiler-rt/test/hwasan/TestCases/memcmp.cpp
@@ -3,11 +3,17 @@
 // 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 <assert.h>
 #include <sanitizer/hwasan_interface.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
+__attribute__((no_sanitize("hwaddress"))) void
+ForceCallInterceptor(void *p, const void *a, size_t size) {
+  assert(memcmp(p, a, size) == 0);
+}
+
 int main(int argc, char **argv) {
   __hwasan_enable_allocator_tagging();
   char a[] = {static_cast<char>(argc), 2, 3, 4};
@@ -15,13 +21,14 @@ int main(int argc, char **argv) {
   char *p = (char *)malloc(size);
   memcpy(p, a, size);
   free(p);
-  return memcmp(p, a, size);
+  ForceCallInterceptor(p, a, size);
+  return 0;
   // CHECK: HWAddressSanitizer: tag-mismatch on address
   // CHECK: READ of size 4
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-3]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-4]]
   // CHECK: Cause: use-after-free
   // CHECK: freed by thread
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-7]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-8]]
   // CHECK: previously allocated by thread
-  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-11]]
+  // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-12]]
 }


        


More information about the llvm-commits mailing list