[hwasan] Make sure we retag with a new tag on free.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D105021
This commit is contained in:
Florian Mayer 2021-06-28 14:19:43 +01:00
parent 7b7b5b5a26
commit ad8494c021
1 changed files with 3 additions and 1 deletions

View File

@ -196,6 +196,7 @@ static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {
: tagged_ptr;
void *aligned_ptr = reinterpret_cast<void *>(
RoundDownTo(reinterpret_cast<uptr>(untagged_ptr), kShadowAlignment));
tag_t pointer_tag = GetTagFromPointer(reinterpret_cast<uptr>(tagged_ptr));
Metadata *meta =
reinterpret_cast<Metadata *>(allocator.GetMetaData(aligned_ptr));
uptr orig_size = meta->get_requested_size();
@ -236,7 +237,8 @@ static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {
// The tag can be zero if tagging is disabled on this thread.
do {
tag = t->GenerateRandomTag(/*num_bits=*/8);
} while (UNLIKELY(tag < kShadowAlignment && tag != 0));
} while (
UNLIKELY((tag < kShadowAlignment || tag == pointer_tag) && tag != 0));
} else {
static_assert(kFallbackFreeTag >= kShadowAlignment,
"fallback tag must not be a short granule tag.");