[compiler-rt] ff1329e - [HWASAN] Add bcmp interceptor (#69257)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 16 16:09:49 PDT 2023
Author: Kirill Stoimenov
Date: 2023-10-16T16:09:44-07:00
New Revision: ff1329e29709477472a93e9ce975f166f75999a3
URL: https://github.com/llvm/llvm-project/commit/ff1329e29709477472a93e9ce975f166f75999a3
DIFF: https://github.com/llvm/llvm-project/commit/ff1329e29709477472a93e9ce975f166f75999a3.diff
LOG: [HWASAN] Add bcmp interceptor (#69257)
Added:
compiler-rt/test/hwasan/TestCases/bcmp.cpp
Modified:
compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h b/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
index 390c9d80c38edd9..86d26b5ac12d4a7 100644
--- a/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
+++ b/compiler-rt/lib/hwasan/hwasan_platform_interceptors.h
@@ -68,8 +68,8 @@
// #undef SANITIZER_INTERCEPT_MEMCMP
// #define SANITIZER_INTERCEPT_MEMCMP 0
-#undef SANITIZER_INTERCEPT_BCMP
-#define SANITIZER_INTERCEPT_BCMP 0
+// #undef SANITIZER_INTERCEPT_BCMP
+// #define SANITIZER_INTERCEPT_BCMP 0
#undef SANITIZER_INTERCEPT_STRNDUP
#define SANITIZER_INTERCEPT_STRNDUP 0
diff --git a/compiler-rt/test/hwasan/TestCases/bcmp.cpp b/compiler-rt/test/hwasan/TestCases/bcmp.cpp
new file mode 100644
index 000000000000000..3dee4b8490efc06
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/bcmp.cpp
@@ -0,0 +1,27 @@
+// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// 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 <sanitizer/hwasan_interface.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ __hwasan_enable_allocator_tagging();
+ char a[] = {static_cast<char>(argc), 2, 3, 4};
+ int size = sizeof(a);
+ char *p = (char *)malloc(size);
+ memcpy(p, a, size);
+ free(p);
+ return bcmp(p, a, size);
+ // CHECK: HWAddressSanitizer: tag-mismatch on address
+ // CHECK: READ of size 4
+ // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-3]]
+ // CHECK: Cause: use-after-free
+ // CHECK: freed by thread
+ // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-7]]
+ // CHECK: previously allocated by thread
+ // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}bcmp.cpp:[[@LINE-11]]
+}
More information about the llvm-commits
mailing list