[compiler-rt] [HWASan] Prevent same tag for adjacent heap objects (PR #69337)

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 15:52:07 PDT 2023


================
@@ -237,7 +237,10 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
   if (InTaggableRegion(reinterpret_cast<uptr>(user_ptr)) &&
       atomic_load_relaxed(&hwasan_allocator_tagging_enabled) &&
       flags()->tag_in_malloc && malloc_bisect(stack, orig_size)) {
-    tag_t tag = t ? t->GenerateRandomTag() : kFallbackAllocTag;
+    tag_t tag = t ? t->GenerateRandomNonCollidingTag((uptr)user_ptr - 1,
----------------
eugenis wrote:

I'd rather do the same as in the Deallocate code - call GenerateRandomTag() in a loop until it returns a suitable tag. You could try lifting the (!tag) check from GenerateRandomTag to its callers to remove one nested loop, but make sure not to miss any :)

https://github.com/llvm/llvm-project/pull/69337


More information about the llvm-commits mailing list