[compiler-rt] [msan] Mark allocator padding as uninitialized, with new origin tag (PR #157187)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 6 12:27:24 PDT 2025
================
@@ -217,25 +217,44 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
}
auto *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(allocated));
meta->requested_size = size;
+ uptr actually_allocated_size = allocator.GetActuallyAllocatedSize(allocated);
+ void* padding_start =
+ reinterpret_cast<void*>(reinterpret_cast<uptr>(allocated) + size);
+ uptr padding_size = actually_allocated_size - size;
+
+ // Origins have 4-byte granularity. Set the TAG_ALLOC_PADDING origin first,
+ // so the TAG_ALLOC origin will take precedence if necessary e.g.,
+ // - if we have malloc(7) that actually takes up 16 bytes:
+ // bytes 0-7: uninitialized, origin TAG_ALLOC
+ // bytes 8-15: uninitialized, origin TAG_ALLOC_PADDING
+ // - with calloc(7,1):
+ // bytes 0-6: initialized, origin not set (and irrelevant)
+ // byte 7: uninitialized, origin TAG_ALLOC_PADDING (unlike malloc)
+ // bytes 8-15: uninitialized, origin TAG_ALLOC_PADDING
+ if (__msan_get_track_origins() && flags()->poison_in_malloc) {
----------------
vitalybuka wrote:
I would recommend to move it next to corresponding __msan_poison
Now reader needs to guess whare it coming from
also you probably will save on on if __msan_get_track_origins, which probably negligle
but Origin::CreateHeapOrigin(stack); is expensive
https://github.com/llvm/llvm-project/pull/157187
More information about the llvm-commits
mailing list