1616#include " hwasan_allocator.h"
1717#include " hwasan_mapping.h"
1818#include " hwasan_thread.h"
19- #include " hwasan_thread_list.h"
2019#include " sanitizer_common/sanitizer_allocator_internal.h"
2120#include " sanitizer_common/sanitizer_common.h"
2221#include " sanitizer_common/sanitizer_flags.h"
@@ -36,31 +35,6 @@ static StackTrace GetStackTraceFromId(u32 id) {
3635 return res;
3736}
3837
39- // A RAII object that holds a copy of the current thread stack ring buffer.
40- // The actual stack buffer may change while we are iterating over it (for
41- // example, Printf may call syslog() which can itself be built with hwasan).
42- class SavedStackAllocations {
43- public:
44- SavedStackAllocations (StackAllocationsRingBuffer *rb) {
45- uptr size = rb->size () * sizeof (uptr);
46- void *storage =
47- MmapAlignedOrDieOnFatalError (size, size * 2 , " saved stack allocations" );
48- new (&rb_) StackAllocationsRingBuffer (*rb, storage);
49- }
50-
51- ~SavedStackAllocations () {
52- StackAllocationsRingBuffer *rb = get ();
53- UnmapOrDie (rb->StartOfStorage (), rb->size () * sizeof (uptr));
54- }
55-
56- StackAllocationsRingBuffer *get () {
57- return (StackAllocationsRingBuffer *)&rb_;
58- }
59-
60- private:
61- uptr rb_;
62- };
63-
6438class Decorator : public __sanitizer ::SanitizerCommonDecorator {
6539 public:
6640 Decorator () : SanitizerCommonDecorator() { }
@@ -89,9 +63,7 @@ uptr FindHeapAllocation(HeapAllocationsRingBuffer *rb,
8963 return 0 ;
9064}
9165
92- void PrintAddressDescription (
93- uptr tagged_addr, uptr access_size,
94- StackAllocationsRingBuffer *current_stack_allocations) {
66+ void PrintAddressDescription (uptr tagged_addr, uptr access_size) {
9567 Decorator d;
9668 int num_descriptions_printed = 0 ;
9769 uptr untagged_addr = UntagAddr (tagged_addr);
@@ -137,7 +109,7 @@ void PrintAddressDescription(
137109 }
138110 }
139111
140- hwasanThreadList (). VisitAllLiveThreads ([&](Thread *t) {
112+ Thread:: VisitAllLiveThreads ([&](Thread *t) {
141113 // Scan all threads' ring buffers to find if it's a heap-use-after-free.
142114 HeapAllocationRecord har;
143115 if (uptr D = FindHeapAllocation (t->heap_allocations (), tagged_addr, &har)) {
@@ -173,25 +145,6 @@ void PrintAddressDescription(
173145 Printf (" %s" , d.Default ());
174146 t->Announce ();
175147
176- // Temporary report section, needs to be improved.
177- Printf (" Previosly allocated frames:\n " );
178- auto *sa = (t == GetCurrentThread () && current_stack_allocations)
179- ? current_stack_allocations
180- : t->stack_allocations ();
181- uptr frames = Min ((uptr)flags ()->stack_history_size , sa->size ());
182- for (uptr i = 0 ; i < frames; i++) {
183- uptr record = (*sa)[i];
184- if (!record)
185- break ;
186- uptr sp = (record >> 48 ) << 4 ;
187- uptr pc_mask = (1ULL << 48 ) - 1 ;
188- uptr pc = record & pc_mask;
189- uptr fixed_pc = StackTrace::GetNextInstructionPc (pc);
190- StackTrace stack (&fixed_pc, 1 );
191- Printf (" record: %p pc: %p sp: %p" , record, pc, sp);
192- stack.Print ();
193- }
194-
195148 num_descriptions_printed++;
196149 }
197150 });
@@ -217,16 +170,13 @@ void ReportStats() {}
217170void ReportInvalidAccessInsideAddressRange (const char *what, const void *start,
218171 uptr size, uptr offset) {
219172 ScopedErrorReportLock l;
220- SavedStackAllocations current_stack_allocations (
221- GetCurrentThread ()->stack_allocations ());
222173
223174 Decorator d;
224175 Printf (" %s" , d.Warning ());
225176 Printf (" %sTag mismatch in %s%s%s at offset %zu inside [%p, %zu)%s\n " ,
226177 d.Warning (), d.Name (), what, d.Warning (), offset, start, size,
227178 d.Default ());
228- PrintAddressDescription ((uptr)start + offset, 1 ,
229- current_stack_allocations.get ());
179+ PrintAddressDescription ((uptr)start + offset, 1 );
230180 // if (__sanitizer::Verbosity())
231181 // DescribeMemoryRange(start, size);
232182}
@@ -274,7 +224,7 @@ void ReportInvalidFree(StackTrace *stack, uptr tagged_addr) {
274224
275225 stack->Print ();
276226
277- PrintAddressDescription (tagged_addr, 0 , nullptr );
227+ PrintAddressDescription (tagged_addr, 0 );
278228
279229 PrintTagsAroundAddr (tag_ptr);
280230
@@ -285,8 +235,6 @@ void ReportInvalidFree(StackTrace *stack, uptr tagged_addr) {
285235void ReportTagMismatch (StackTrace *stack, uptr tagged_addr, uptr access_size,
286236 bool is_store) {
287237 ScopedErrorReportLock l;
288- SavedStackAllocations current_stack_allocations (
289- GetCurrentThread ()->stack_allocations ());
290238
291239 Decorator d;
292240 Printf (" %s" , d.Error ());
@@ -310,8 +258,7 @@ void ReportTagMismatch(StackTrace *stack, uptr tagged_addr, uptr access_size,
310258
311259 stack->Print ();
312260
313- PrintAddressDescription (tagged_addr, access_size,
314- current_stack_allocations.get ());
261+ PrintAddressDescription (tagged_addr, access_size);
315262 t->Announce ();
316263
317264 PrintTagsAroundAddr (tag_ptr);
0 commit comments