[compiler-rt] 29f8e23 - [TEST][hwasan] Check more details in overflow test (#67059)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 14:13:47 PDT 2023


Author: Vitaly Buka
Date: 2023-09-21T14:13:42-07:00
New Revision: 29f8e23ab8a009f074c58d05a1ad5a14c80645c8

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

LOG: [TEST][hwasan] Check more details in overflow test (#67059)

Added: 
    

Modified: 
    compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c
index 32556c37b327538..829a82fa5f3553d 100644
--- a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c
+++ b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c
@@ -1,8 +1,12 @@
 // RUN: %clang_hwasan  %s -o %t
-// RUN: not %run %t 5 10 2>&1 | FileCheck %s --check-prefix=CHECK5
-// RUN: not %run %t 7 10 2>&1 | FileCheck %s --check-prefix=CHECK7
-// RUN: not %run %t 8 20 2>&1 | FileCheck %s --check-prefix=CHECK8
-// RUN: not %run %t 32 20 2>&1 | FileCheck %s --check-prefix=CHECK32
+// RUN: not %run %t   5  10  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK5
+// RUN: not %run %t   7  10  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK7
+// RUN: not %run %t   8  20  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK8
+// RUN: not %run %t 295 300  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK295
+// RUN: not %run %t   1 550 550 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK1
+
+// Full granule.
+// RUN: not %run %t  32  20  26 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_FULL,CHECK32
 
 #include <sanitizer/hwasan_interface.h>
 #include <stdio.h>
@@ -15,16 +19,43 @@ int main(int argc, char **argv) {
     fprintf(stderr, "Invalid number of arguments.");
     abort();
   }
-  int read_offset = argc < 2 ? 5 : atoi(argv[1]);
-  int size = argc < 3 ? 10 : atoi(argv[2]);
-  char *volatile x = (char *)malloc(size);
-  memset(x + read_offset, 0, 26);
+  int read_offset = atoi(argv[1]);
+  int size = atoi(argv[2]);
+  int access_size = atoi(argv[3]);
+  while (1) {
+    char *volatile x = (char *)malloc(size);
+    if (__hwasan_test_shadow(x, size + 1) == size)
+      memset(x + read_offset, 0, access_size);
+    free(x);
+  }
+
+  // CHECK_SMALL: WRITE of size {{26|550}} at {{.*}} tags: [[TAG:[0-9a-f]+]]/{{[0-9a-f]+}}([[TAG]]) (ptr/mem)
+  // CHECK_FULL: WRITE of size 26 at {{.*}} tags: [[TAG:[0-9a-f]+]]/00 (ptr/mem)
+
   // CHECK5: Invalid access starting at offset 5
   // CHECK5: is located 5 bytes inside a 10-byte region
   // CHECK7: Invalid access starting at offset 3
   // CHECK7: is located 7 bytes inside a 10-byte region
   // CHECK8: Invalid access starting at offset 12
   // CHECK8: is located 8 bytes inside a 20-byte region
+  // CHECK295: Invalid access starting at offset 5
+  // CHECK295: is located 295 bytes inside a 300-byte region
+  // CHECK1: Invalid access starting at offset 549
+  // CHECK1: is located 1 bytes inside a 550-byte region
+
+  // CHECK32-NOT: Invalid access starting at offset
   // CHECK32: is located 12 bytes after a 20-byte region
-  free(x);
+
+  // CHECK-LABEL: Memory tags around the buggy address
+  // CHECK5: =>{{.*}}[0a]
+  // CHECK7: =>{{.*}}[0a]
+  // CHECK8: =>{{.*}}[04]
+  // CHECK295: =>{{.*}}[0c]
+  // CHECK1: =>{{.*}}[06]
+
+  // CHECK32: =>{{.*}}[00]
+
+  // CHECK-LABEL: Tags for short granules around the buggy address
+  // CHECK_SMALL: =>{{.*}}{{\[}}[[TAG]]{{\]}}
+  // CHECK_FULL: =>{{.*}}[..]
 }


        


More information about the llvm-commits mailing list