[compiler-rt] f7c2833 - [HWASan] Leave pointer tagged when calling memmove.
Matt Morehouse via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 28 06:16:05 PST 2022
Author: Matt Morehouse
Date: 2022-01-28T06:15:38-08:00
New Revision: f7c28332de71e55f1ab1b0fef72d598e427db3c3
URL: https://github.com/llvm/llvm-project/commit/f7c28332de71e55f1ab1b0fef72d598e427db3c3
DIFF: https://github.com/llvm/llvm-project/commit/f7c28332de71e55f1ab1b0fef72d598e427db3c3.diff
LOG: [HWASan] Leave pointer tagged when calling memmove.
Fixes a false positive that occurs when a user-implemented memmove is
instrumented by HWASan.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D118180
Added:
compiler-rt/test/hwasan/TestCases/custom-memmove.c
Modified:
compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp b/compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp
index fab017aae60be..ea7f5ce40b074 100644
--- a/compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp
@@ -40,5 +40,5 @@ void *__hwasan_memmove(void *to, const void *from, uptr size) {
reinterpret_cast<uptr>(to), size);
CheckAddressSized<ErrorAction::Recover, AccessType::Load>(
reinterpret_cast<uptr>(from), size);
- return memmove(UntagPtr(to), UntagPtr(from), size);
+ return memmove(to, from, size);
}
diff --git a/compiler-rt/test/hwasan/TestCases/custom-memmove.c b/compiler-rt/test/hwasan/TestCases/custom-memmove.c
new file mode 100644
index 0000000000000..7b15e06234deb
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/custom-memmove.c
@@ -0,0 +1,39 @@
+// Test that custom memmove implementations instrumented by HWASan do not cause
+// false positives.
+
+// RUN: %clang_hwasan %s -o %t
+// RUN: %run %t
+
+#include <assert.h>
+#include <sanitizer/hwasan_interface.h>
+#include <stdlib.h>
+
+void *memmove(void *Dest, const void *Src, size_t N) {
+ char *Tmp = (char *)malloc(N);
+ char *D = (char *)Dest;
+ const char *S = (const char *)Src;
+
+ for (size_t I = 0; I < N; ++I)
+ Tmp[I] = S[I];
+ for (size_t I = 0; I < N; ++I)
+ D[I] = Tmp[I];
+
+ free(Tmp);
+ return Dest;
+}
+
+int main() {
+ __hwasan_enable_allocator_tagging();
+
+ const size_t BufSize = 64;
+ char *Buf = (char *)malloc(BufSize);
+
+ for (size_t I = 0; I < BufSize; ++I)
+ Buf[I] = I;
+ memmove(Buf + BufSize / 2, Buf, BufSize / 2);
+ for (size_t I = 0; I < BufSize; ++I)
+ assert(Buf[I] == I % (BufSize / 2));
+
+ free(Buf);
+ return 0;
+}
More information about the llvm-commits
mailing list