[compiler-rt] 4c83674 - [HWASAN] Fix HwasanReallocate in aliasing mode

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 18:48:42 PDT 2023


Author: Vitaly Buka
Date: 2023-04-26T18:48:30-07:00
New Revision: 4c83674679365dd990fef5f834a07ad32798e7f2

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

LOG: [HWASAN] Fix HwasanReallocate in aliasing mode

HWASAN_ALIASING_MODE needs to untag only
primary allocator pointers.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D149293

Added: 
    

Modified: 
    compiler-rt/lib/hwasan/hwasan_allocator.cpp
    compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
index 3bb7594cf7317..a21de0e54ad50 100644
--- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp
@@ -384,9 +384,12 @@ static void *HwasanReallocate(StackTrace *stack, void *tagged_ptr_old,
   if (tagged_ptr_old && tagged_ptr_new) {
     Metadata *meta =
         reinterpret_cast<Metadata *>(allocator.GetMetaData(untagged_ptr_old));
-    internal_memcpy(
-        UntagPtr(tagged_ptr_new), untagged_ptr_old,
-        Min(new_size, static_cast<uptr>(meta->GetRequestedSize())));
+    void *untagged_ptr_new =
+        InTaggableRegion(reinterpret_cast<uptr>(tagged_ptr_new))
+            ? UntagPtr(tagged_ptr_new)
+            : tagged_ptr_new;
+    internal_memcpy(untagged_ptr_new, untagged_ptr_old,
+                    Min(new_size, static_cast<uptr>(meta->GetRequestedSize())));
     HwasanDeallocate(stack, tagged_ptr_old);
   }
   return tagged_ptr_new;

diff  --git a/compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp b/compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp
index ca3baaa6ec7d0..44f2935434e89 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp
@@ -43,9 +43,6 @@
 // win32 is disabled due to failing errno tests.
 // UNSUPPORTED: ubsan, target={{.*windows-msvc.*}}
 
-// FIXME: Something crashes.
-// XFAIL: hwasan-aliasing
-
 #include <assert.h>
 #include <errno.h>
 #include <limits>


        


More information about the llvm-commits mailing list