[compiler-rt] [msan] Mark allocator padding as uninitialized, with new origin tag (PR #157187)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 12:51:16 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) {
----------------
thurstond wrote:
Done: https://github.com/llvm/llvm-project/pull/157187/commits/69bf31156bf31423f93379707d1b1002130c5f5d
https://github.com/llvm/llvm-project/pull/157187
More information about the llvm-commits
mailing list