16
16
#include " hwasan_allocator.h"
17
17
#include " hwasan_mapping.h"
18
18
#include " hwasan_thread.h"
19
- #include " hwasan_thread_list.h"
20
19
#include " sanitizer_common/sanitizer_allocator_internal.h"
21
20
#include " sanitizer_common/sanitizer_common.h"
22
21
#include " sanitizer_common/sanitizer_flags.h"
@@ -36,31 +35,6 @@ static StackTrace GetStackTraceFromId(u32 id) {
36
35
return res;
37
36
}
38
37
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
-
64
38
class Decorator : public __sanitizer ::SanitizerCommonDecorator {
65
39
public:
66
40
Decorator () : SanitizerCommonDecorator() { }
@@ -89,9 +63,7 @@ uptr FindHeapAllocation(HeapAllocationsRingBuffer *rb,
89
63
return 0 ;
90
64
}
91
65
92
- void PrintAddressDescription (
93
- uptr tagged_addr, uptr access_size,
94
- StackAllocationsRingBuffer *current_stack_allocations) {
66
+ void PrintAddressDescription (uptr tagged_addr, uptr access_size) {
95
67
Decorator d;
96
68
int num_descriptions_printed = 0 ;
97
69
uptr untagged_addr = UntagAddr (tagged_addr);
@@ -137,7 +109,7 @@ void PrintAddressDescription(
137
109
}
138
110
}
139
111
140
- hwasanThreadList (). VisitAllLiveThreads ([&](Thread *t) {
112
+ Thread:: VisitAllLiveThreads ([&](Thread *t) {
141
113
// Scan all threads' ring buffers to find if it's a heap-use-after-free.
142
114
HeapAllocationRecord har;
143
115
if (uptr D = FindHeapAllocation (t->heap_allocations (), tagged_addr, &har)) {
@@ -173,25 +145,6 @@ void PrintAddressDescription(
173
145
Printf (" %s" , d.Default ());
174
146
t->Announce ();
175
147
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
-
195
148
num_descriptions_printed++;
196
149
}
197
150
});
@@ -217,16 +170,13 @@ void ReportStats() {}
217
170
void ReportInvalidAccessInsideAddressRange (const char *what, const void *start,
218
171
uptr size, uptr offset) {
219
172
ScopedErrorReportLock l;
220
- SavedStackAllocations current_stack_allocations (
221
- GetCurrentThread ()->stack_allocations ());
222
173
223
174
Decorator d;
224
175
Printf (" %s" , d.Warning ());
225
176
Printf (" %sTag mismatch in %s%s%s at offset %zu inside [%p, %zu)%s\n " ,
226
177
d.Warning (), d.Name (), what, d.Warning (), offset, start, size,
227
178
d.Default ());
228
- PrintAddressDescription ((uptr)start + offset, 1 ,
229
- current_stack_allocations.get ());
179
+ PrintAddressDescription ((uptr)start + offset, 1 );
230
180
// if (__sanitizer::Verbosity())
231
181
// DescribeMemoryRange(start, size);
232
182
}
@@ -274,7 +224,7 @@ void ReportInvalidFree(StackTrace *stack, uptr tagged_addr) {
274
224
275
225
stack->Print ();
276
226
277
- PrintAddressDescription (tagged_addr, 0 , nullptr );
227
+ PrintAddressDescription (tagged_addr, 0 );
278
228
279
229
PrintTagsAroundAddr (tag_ptr);
280
230
@@ -285,8 +235,6 @@ void ReportInvalidFree(StackTrace *stack, uptr tagged_addr) {
285
235
void ReportTagMismatch (StackTrace *stack, uptr tagged_addr, uptr access_size,
286
236
bool is_store) {
287
237
ScopedErrorReportLock l;
288
- SavedStackAllocations current_stack_allocations (
289
- GetCurrentThread ()->stack_allocations ());
290
238
291
239
Decorator d;
292
240
Printf (" %s" , d.Error ());
@@ -310,8 +258,7 @@ void ReportTagMismatch(StackTrace *stack, uptr tagged_addr, uptr access_size,
310
258
311
259
stack->Print ();
312
260
313
- PrintAddressDescription (tagged_addr, access_size,
314
- current_stack_allocations.get ());
261
+ PrintAddressDescription (tagged_addr, access_size);
315
262
t->Announce ();
316
263
317
264
PrintTagsAroundAddr (tag_ptr);
0 commit comments