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

Evgenii Stepanov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 16:27:28 PDT 2023


================
@@ -156,6 +156,35 @@ tag_t Thread::GenerateRandomTag(uptr num_bits) {
   return tag;
 }
 
+// Generate a (pseudo-)random non-zero tag and prevent collisions to neighboring
+// objects.
+tag_t Thread::GenerateRandomNonCollidingTag(uptr prev_ptr, uptr foll_ptr,
+                                            uptr num_bits) {
+  DCHECK_GT(num_bits, 0);
+  if (tagging_disabled_)
+    return 0;
+  tag_t tag;
+  tag_t previous_tag = *(tag_t *)MemToShadow(prev_ptr);
----------------
eugenis wrote:

This feature if done right should not add any new branches though. We already exclude tag value zero; adding two more is just OR-merging two more conditions to the same branch. 

But please do not duplicate the code. Either move tagging_disabled_ check to the callers as well, or factor out the common part into an inline helper function.

And I'd prefer if prev/next tags were passed by value. This function does not need to know about MemToShadow.

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


More information about the llvm-commits mailing list