Skip to content

Commit ac750e2

Browse files
committed
[NFC][hwasan] Stored tail early (#66682)
1 parent ddedad8 commit ac750e2

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

compiler-rt/lib/hwasan/hwasan_report.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -764,24 +764,28 @@ class TailOverwrittenReport : public BaseReport {
764764
uptr orig_size, const u8 *expected)
765765
: BaseReport(stack, flags()->halt_on_error, tagged_addr, 0),
766766
orig_size(orig_size),
767-
expected(expected) {}
767+
tail_size(kShadowAlignment - (orig_size % kShadowAlignment)) {
768+
CHECK_GT(tail_size, 0U);
769+
CHECK_LT(tail_size, kShadowAlignment);
770+
internal_memcpy(tail_copy,
771+
reinterpret_cast<u8 *>(untagged_addr + orig_size),
772+
tail_size);
773+
internal_memcpy(actual_expected, expected, tail_size);
774+
// Short granule is stashed in the last byte of the magic string. To avoid
775+
// confusion, make the expected magic string contain the short granule tag.
776+
if (orig_size % kShadowAlignment != 0)
777+
actual_expected[tail_size - 1] = ptr_tag;
778+
}
768779
~TailOverwrittenReport();
769780

770781
private:
771-
const uptr orig_size;
772-
const u8 *expected;
782+
const uptr orig_size = 0;
783+
const uptr tail_size = 0;
784+
u8 actual_expected[kShadowAlignment] = {};
785+
u8 tail_copy[kShadowAlignment] = {};
773786
};
774787

775788
TailOverwrittenReport::~TailOverwrittenReport() {
776-
uptr tail_size = kShadowAlignment - (orig_size % kShadowAlignment);
777-
u8 actual_expected[kShadowAlignment];
778-
internal_memcpy(actual_expected, expected, tail_size);
779-
// Short granule is stashed in the last byte of the magic string. To avoid
780-
// confusion, make the expected magic string contain the short granule tag.
781-
if (orig_size % kShadowAlignment != 0) {
782-
actual_expected[tail_size - 1] = ptr_tag;
783-
}
784-
785789
Decorator d;
786790
Printf("%s", d.Error());
787791
const char *bug_type = "allocation-tail-overwritten";
@@ -803,9 +807,7 @@ TailOverwrittenReport::~TailOverwrittenReport() {
803807
}
804808

805809
InternalScopedString s;
806-
CHECK_GT(tail_size, 0U);
807-
CHECK_LT(tail_size, kShadowAlignment);
808-
u8 *tail = reinterpret_cast<u8*>(untagged_addr + orig_size);
810+
u8 *tail = tail_copy;
809811
s.AppendF("Tail contains: ");
810812
for (uptr i = 0; i < kShadowAlignment - tail_size; i++) s.AppendF(".. ");
811813
for (uptr i = 0; i < tail_size; i++) s.AppendF("%02x ", tail[i]);

0 commit comments

Comments
 (0)