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

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 13:23:44 PDT 2023


https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/67059

None

>From 48886549db8426961b0e78abd493a090eba4c9dd Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Thu, 21 Sep 2023 13:20:11 -0700
Subject: [PATCH] [TEST][hwasan] Check more details in overflow test

---
 .../TestCases/heap-buffer-overflow-into.c     | 37 ++++++++++++++++---
 1 file changed, 32 insertions(+), 5 deletions(-)

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..32c939c06a801ef 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 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK5
+// RUN: not %run %t 7 10 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK7
+// RUN: not %run %t 8 20 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK8
+// RUN: not %run %t 295 300 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK295
+// RUN: not %run %t 1 550 560 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_SMALL,CHECK1
+
+// These hit full granule.
+// RUN: not %run %t 32 20 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK_FULL,CHECK32
 
 #include <sanitizer/hwasan_interface.h>
 #include <stdio.h>
@@ -17,14 +21,37 @@ int main(int argc, char **argv) {
   }
   int read_offset = argc < 2 ? 5 : atoi(argv[1]);
   int size = argc < 3 ? 10 : atoi(argv[2]);
+  int access_size = argc < 4 ? 26 : atoi(argv[3]);
   char *volatile x = (char *)malloc(size);
-  memset(x + read_offset, 0, 26);
+  memset(x + read_offset, 0, access_size);
+  // CHECK_SMALL: WRITE of size {{26|560}} 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
+
+  // 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: =>{{.*}}[..]
   free(x);
 }



More information about the llvm-commits mailing list