Skip to content

Commit fa32100

Browse files
committed
libsanitizer: merge from upstream (61a6439f35b6de28)
1 parent b8ecd96 commit fa32100

238 files changed

Lines changed: 7276 additions & 4764 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libsanitizer/MERGE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
c425db2eb558c26377edc04e062c0c1f999b2770
1+
61a6439f35b6de28ff4aff4450d6fca970292fd5
22

33
The first line of this file holds the git revision number of the
44
last merge done from the master library sources.

libsanitizer/asan/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ asan_files = \
4646
asan_suppressions.cpp \
4747
asan_thread.cpp \
4848
asan_win.cpp \
49-
asan_win_dll_thunk.cpp \
5049
asan_win_dynamic_runtime_thunk.cpp \
5150
asan_interceptors_vfork.S
5251

libsanitizer/asan/Makefile.in

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ am__objects_1 = asan_activation.lo asan_allocator.lo asan_debugging.lo \
160160
asan_posix.lo asan_premap_shadow.lo asan_report.lo asan_rtl.lo \
161161
asan_shadow_setup.lo asan_stack.lo asan_stats.lo \
162162
asan_suppressions.lo asan_thread.lo asan_win.lo \
163-
asan_win_dll_thunk.lo asan_win_dynamic_runtime_thunk.lo \
164-
asan_interceptors_vfork.lo
163+
asan_win_dynamic_runtime_thunk.lo asan_interceptors_vfork.lo
165164
am_libasan_la_OBJECTS = $(am__objects_1)
166165
libasan_la_OBJECTS = $(am_libasan_la_OBJECTS)
167166
AM_V_lt = $(am__v_lt_@AM_V@)
@@ -457,7 +456,6 @@ asan_files = \
457456
asan_suppressions.cpp \
458457
asan_thread.cpp \
459458
asan_win.cpp \
460-
asan_win_dll_thunk.cpp \
461459
asan_win_dynamic_runtime_thunk.cpp \
462460
asan_interceptors_vfork.S
463461

@@ -619,7 +617,6 @@ distclean-compile:
619617
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asan_suppressions.Plo@am__quote@
620618
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asan_thread.Plo@am__quote@
621619
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asan_win.Plo@am__quote@
622-
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asan_win_dll_thunk.Plo@am__quote@
623620
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asan_win_dynamic_runtime_thunk.Plo@am__quote@
624621

625622
.S.o:

libsanitizer/asan/asan_allocator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,15 @@ struct Allocator {
717717
return;
718718
}
719719

720-
RunFreeHooks(ptr);
720+
if (RunFreeHooks(ptr)) {
721+
// Someone used __sanitizer_ignore_free_hook() and decided that they
722+
// didn't want the memory to __sanitizer_ignore_free_hook freed right now.
723+
// When they call free() on this pointer again at a later time, we should
724+
// ignore the alloc-type mismatch and allow them to deallocate the pointer
725+
// through free(), rather than the initial alloc type.
726+
m->alloc_type = FROM_MALLOC;
727+
return;
728+
}
721729

722730
// Must mark the chunk as quarantined before any changes to its metadata.
723731
// Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag.

libsanitizer/asan/asan_allocator.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,42 +182,44 @@ static_assert(SizeClassMap::kNumClassesRounded <= 32,
182182
"allocator size and SizeClassMap tunings that allows us to "
183183
"reliably run all bringup tests in a sanitized environment.");
184184

185-
# else
185+
# else // SANITIZER_RISCV64
186186
// These are the default allocator tunings for non-RISCV environments where the
187187
// VMA is usually 48 bits and we have lots of space.
188188
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
189189
typedef DefaultSizeClassMap SizeClassMap;
190-
# endif
191-
# elif defined(__powerpc64__)
190+
# endif // SANITIZER_RISCV64
191+
# else // SANITIZER_FUCHSIA
192+
193+
# if SANITIZER_APPLE
194+
const uptr kAllocatorSpace = 0x600000000000ULL;
195+
# else // SANITIZER_APPLE
192196
const uptr kAllocatorSpace = ~(uptr)0;
197+
# endif // SANITIZER_APPLE
198+
199+
# if defined(__powerpc64__)
193200
const uptr kAllocatorSize = 0x20000000000ULL; // 2T.
194201
typedef DefaultSizeClassMap SizeClassMap;
195-
# elif defined(__aarch64__) && SANITIZER_ANDROID
202+
# elif defined(__aarch64__) && SANITIZER_ANDROID
196203
// Android needs to support 39, 42 and 48 bit VMA.
197-
const uptr kAllocatorSpace = ~(uptr)0;
198204
const uptr kAllocatorSize = 0x2000000000ULL; // 128G.
199205
typedef VeryCompactSizeClassMap SizeClassMap;
200-
# elif SANITIZER_RISCV64
201-
const uptr kAllocatorSpace = ~(uptr)0;
206+
# elif SANITIZER_RISCV64
202207
const uptr kAllocatorSize = 0x2000000000ULL; // 128G.
203208
typedef VeryDenseSizeClassMap SizeClassMap;
204-
# elif defined(__sparc__)
205-
const uptr kAllocatorSpace = ~(uptr)0;
209+
# elif defined(__sparc__)
206210
const uptr kAllocatorSize = 0x20000000000ULL; // 2T.
207211
typedef DefaultSizeClassMap SizeClassMap;
208-
# elif SANITIZER_WINDOWS
209-
const uptr kAllocatorSpace = ~(uptr)0;
212+
# elif SANITIZER_WINDOWS
210213
const uptr kAllocatorSize = 0x8000000000ULL; // 500G
211214
typedef DefaultSizeClassMap SizeClassMap;
212-
# elif SANITIZER_APPLE
213-
const uptr kAllocatorSpace = 0x600000000000ULL;
215+
# elif SANITIZER_APPLE
214216
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
215217
typedef DefaultSizeClassMap SizeClassMap;
216-
# else
217-
const uptr kAllocatorSpace = 0x500000000000ULL;
218+
# else
218219
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
219220
typedef DefaultSizeClassMap SizeClassMap;
220-
# endif
221+
# endif // defined(__powerpc64__) etc.
222+
# endif // SANITIZER_FUCHSIA
221223
template <typename AddressSpaceViewTy>
222224
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
223225
static const uptr kSpaceBeg = kAllocatorSpace;
@@ -232,7 +234,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
232234
template <typename AddressSpaceView>
233235
using PrimaryAllocatorASVT = SizeClassAllocator64<AP64<AddressSpaceView>>;
234236
using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
235-
#else // Fallback to SizeClassAllocator32.
237+
#else // SANITIZER_CAN_USE_ALLOCATOR64. Fallback to SizeClassAllocator32.
236238
typedef CompactSizeClassMap SizeClassMap;
237239
template <typename AddressSpaceViewTy>
238240
struct AP32 {

libsanitizer/asan/asan_descriptions.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,20 @@
2020
namespace __asan {
2121

2222
AsanThreadIdAndName::AsanThreadIdAndName(AsanThreadContext *t) {
23-
Init(t->tid, t->name);
24-
}
25-
26-
AsanThreadIdAndName::AsanThreadIdAndName(u32 tid) {
27-
if (tid == kInvalidTid) {
28-
Init(tid, "");
29-
} else {
30-
asanThreadRegistry().CheckLocked();
31-
AsanThreadContext *t = GetThreadContextByTidLocked(tid);
32-
Init(tid, t->name);
23+
if (!t) {
24+
internal_snprintf(name, sizeof(name), "T-1");
25+
return;
3326
}
27+
int len = internal_snprintf(name, sizeof(name), "T%llu", t->unique_id);
28+
CHECK(((unsigned int)len) < sizeof(name));
29+
if (internal_strlen(t->name))
30+
internal_snprintf(&name[len], sizeof(name) - len, " (%s)", t->name);
3431
}
3532

36-
void AsanThreadIdAndName::Init(u32 tid, const char *tname) {
37-
int len = internal_snprintf(name, sizeof(name), "T%d", tid);
38-
CHECK(((unsigned int)len) < sizeof(name));
39-
if (tname[0] != '\0')
40-
internal_snprintf(&name[len], sizeof(name) - len, " (%s)", tname);
33+
AsanThreadIdAndName::AsanThreadIdAndName(u32 tid)
34+
: AsanThreadIdAndName(
35+
tid == kInvalidTid ? nullptr : GetThreadContextByTidLocked(tid)) {
36+
asanThreadRegistry().CheckLocked();
4137
}
4238

4339
void DescribeThread(AsanThreadContext *context) {
@@ -48,9 +44,20 @@ void DescribeThread(AsanThreadContext *context) {
4844
return;
4945
}
5046
context->announced = true;
47+
48+
AsanThreadContext *parent_context =
49+
context->parent_tid == kInvalidTid
50+
? nullptr
51+
: GetThreadContextByTidLocked(context->parent_tid);
52+
53+
// `context->parent_tid` may point to reused slot. Check `unique_id` which
54+
// is always smaller for the parent, always greater for a new user.
55+
if (context->unique_id <= parent_context->unique_id)
56+
parent_context = nullptr;
57+
5158
InternalScopedString str;
5259
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
53-
if (context->parent_tid == kInvalidTid) {
60+
if (!parent_context) {
5461
str.Append(" created by unknown thread\n");
5562
Printf("%s", str.data());
5663
return;
@@ -60,11 +67,8 @@ void DescribeThread(AsanThreadContext *context) {
6067
Printf("%s", str.data());
6168
StackDepotGet(context->stack_id).Print();
6269
// Recursively described parent thread if needed.
63-
if (flags()->print_full_thread_history) {
64-
AsanThreadContext *parent_context =
65-
GetThreadContextByTidLocked(context->parent_tid);
70+
if (flags()->print_full_thread_history)
6671
DescribeThread(parent_context);
67-
}
6872
}
6973

7074
// Shadow descriptions
@@ -245,11 +249,11 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
245249
InternalScopedString str;
246250
str.AppendF(" [%zd, %zd)", var.beg, var_end);
247251
// Render variable name.
248-
str.AppendF(" '");
252+
str.Append(" '");
249253
for (uptr i = 0; i < var.name_len; ++i) {
250254
str.AppendF("%c", var.name_pos[i]);
251255
}
252-
str.AppendF("'");
256+
str.Append("'");
253257
if (var.line > 0) {
254258
str.AppendF(" (line %zd)", var.line);
255259
}
@@ -260,7 +264,7 @@ static void PrintAccessAndVarIntersection(const StackVarDescr &var, uptr addr,
260264
str.AppendF("%s <== Memory access at offset %zd %s this variable%s\n",
261265
d.Location(), addr, pos_descr, d.Default());
262266
} else {
263-
str.AppendF("\n");
267+
str.Append("\n");
264268
}
265269
Printf("%s", str.data());
266270
}
@@ -292,7 +296,7 @@ static void DescribeAddressRelativeToGlobal(uptr addr, uptr access_size,
292296
str.AppendF(" global variable '%s' defined in '",
293297
MaybeDemangleGlobalName(g.name));
294298
PrintGlobalLocation(&str, g, /*print_module_name=*/false);
295-
str.AppendF("' (0x%zx) of size %zu\n", g.beg, g.size);
299+
str.AppendF("' (%p) of size %zu\n", (void *)g.beg, g.size);
296300
str.Append(d.Default());
297301
PrintGlobalNameIfASCII(&str, g);
298302
Printf("%s", str.data());

libsanitizer/asan/asan_descriptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ class AsanThreadIdAndName {
3535
const char *c_str() const { return &name[0]; }
3636

3737
private:
38-
void Init(u32 tid, const char *tname);
39-
4038
char name[128];
4139
};
4240

libsanitizer/asan/asan_errors.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ void ErrorBadParamsToAnnotateContiguousContainer::Print() {
327327
" old_mid : %p\n"
328328
" new_mid : %p\n",
329329
(void *)beg, (void *)end, (void *)old_mid, (void *)new_mid);
330-
uptr granularity = ASAN_SHADOW_GRANULARITY;
331-
if (!IsAligned(beg, granularity))
332-
Report("ERROR: beg is not aligned by %zu\n", granularity);
333330
stack->Print();
334331
ReportErrorSummary(scariness.GetDescription(), stack);
335332
}
@@ -347,9 +344,20 @@ void ErrorBadParamsToAnnotateDoubleEndedContiguousContainer::Print() {
347344
(void *)storage_beg, (void *)storage_end, (void *)old_container_beg,
348345
(void *)old_container_end, (void *)new_container_beg,
349346
(void *)new_container_end);
350-
uptr granularity = ASAN_SHADOW_GRANULARITY;
351-
if (!IsAligned(storage_beg, granularity))
352-
Report("ERROR: storage_beg is not aligned by %zu\n", granularity);
347+
stack->Print();
348+
ReportErrorSummary(scariness.GetDescription(), stack);
349+
}
350+
351+
void ErrorBadParamsToCopyContiguousContainerAnnotations::Print() {
352+
Report(
353+
"ERROR: AddressSanitizer: bad parameters to "
354+
"__sanitizer_copy_contiguous_container_annotations:\n"
355+
" src_storage_beg : %p\n"
356+
" src_storage_end : %p\n"
357+
" dst_storage_beg : %p\n"
358+
" new_storage_end : %p\n",
359+
(void *)old_storage_beg, (void *)old_storage_end, (void *)new_storage_beg,
360+
(void *)new_storage_end);
353361
stack->Print();
354362
ReportErrorSummary(scariness.GetDescription(), stack);
355363
}

libsanitizer/asan/asan_errors.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,24 @@ struct ErrorBadParamsToAnnotateDoubleEndedContiguousContainer : ErrorBase {
353353
void Print();
354354
};
355355

356+
struct ErrorBadParamsToCopyContiguousContainerAnnotations : ErrorBase {
357+
const BufferedStackTrace *stack;
358+
uptr old_storage_beg, old_storage_end, new_storage_beg, new_storage_end;
359+
360+
ErrorBadParamsToCopyContiguousContainerAnnotations() = default; // (*)
361+
ErrorBadParamsToCopyContiguousContainerAnnotations(
362+
u32 tid, BufferedStackTrace *stack_, uptr old_storage_beg_,
363+
uptr old_storage_end_, uptr new_storage_beg_, uptr new_storage_end_)
364+
: ErrorBase(tid, 10,
365+
"bad-__sanitizer_annotate_double_ended_contiguous_container"),
366+
stack(stack_),
367+
old_storage_beg(old_storage_beg_),
368+
old_storage_end(old_storage_end_),
369+
new_storage_beg(new_storage_beg_),
370+
new_storage_end(new_storage_end_) {}
371+
void Print();
372+
};
373+
356374
struct ErrorODRViolation : ErrorBase {
357375
__asan_global global1, global2;
358376
u32 stack_id1, stack_id2;
@@ -421,6 +439,7 @@ struct ErrorGeneric : ErrorBase {
421439
macro(StringFunctionSizeOverflow) \
422440
macro(BadParamsToAnnotateContiguousContainer) \
423441
macro(BadParamsToAnnotateDoubleEndedContiguousContainer) \
442+
macro(BadParamsToCopyContiguousContainerAnnotations) \
424443
macro(ODRViolation) \
425444
macro(InvalidPointerPair) \
426445
macro(Generic)

0 commit comments

Comments
 (0)