2019-08-01 21:43:28 +08:00
|
|
|
//===-- asan_suppressions.cpp ---------------------------------------------===//
|
2014-12-06 04:26:09 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-12-06 04:26:09 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Issue suppression and suppression-related functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "asan_suppressions.h"
|
|
|
|
|
|
|
|
#include "asan_stack.h"
|
2015-02-21 01:41:59 +08:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
2014-12-06 04:26:09 +08:00
|
|
|
#include "sanitizer_common/sanitizer_suppressions.h"
|
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
|
|
|
|
static SuppressionContext *suppression_ctx = nullptr;
|
|
|
|
static const char kInterceptorName[] = "interceptor_name";
|
|
|
|
static const char kInterceptorViaFunction[] = "interceptor_via_fun";
|
|
|
|
static const char kInterceptorViaLibrary[] = "interceptor_via_lib";
|
2015-02-25 08:49:12 +08:00
|
|
|
static const char kODRViolation[] = "odr_violation";
|
2015-02-21 01:41:59 +08:00
|
|
|
static const char *kSuppressionTypes[] = {
|
2015-02-25 08:49:12 +08:00
|
|
|
kInterceptorName, kInterceptorViaFunction, kInterceptorViaLibrary,
|
|
|
|
kODRViolation};
|
2014-12-06 04:26:09 +08:00
|
|
|
|
2017-01-29 13:44:59 +08:00
|
|
|
SANITIZER_INTERFACE_WEAK_DEF(const char *, __asan_default_suppressions, void) {
|
|
|
|
return "";
|
|
|
|
}
|
2015-02-26 00:00:26 +08:00
|
|
|
|
2014-12-06 04:26:09 +08:00
|
|
|
void InitializeSuppressions() {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK_EQ(nullptr, suppression_ctx);
|
2019-09-12 07:19:48 +08:00
|
|
|
suppression_ctx = new (suppression_placeholder)
|
2015-02-21 01:41:59 +08:00
|
|
|
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
|
|
|
|
suppression_ctx->ParseFromFile(flags()->suppressions);
|
2015-02-26 00:00:26 +08:00
|
|
|
if (&__asan_default_suppressions)
|
|
|
|
suppression_ctx->Parse(__asan_default_suppressions());
|
2014-12-06 04:26:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInterceptorSuppressed(const char *interceptor_name) {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
2014-12-06 04:26:09 +08:00
|
|
|
Suppression *s;
|
|
|
|
// Match "interceptor_name" suppressions.
|
2015-02-21 01:41:59 +08:00
|
|
|
return suppression_ctx->Match(interceptor_name, kInterceptorName, &s);
|
2014-12-06 04:26:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HaveStackTraceBasedSuppressions() {
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
|
|
|
return suppression_ctx->HasSuppressionType(kInterceptorViaFunction) ||
|
|
|
|
suppression_ctx->HasSuppressionType(kInterceptorViaLibrary);
|
2014-12-06 04:26:09 +08:00
|
|
|
}
|
|
|
|
|
2015-02-25 08:49:12 +08:00
|
|
|
bool IsODRViolationSuppressed(const char *global_var_name) {
|
|
|
|
CHECK(suppression_ctx);
|
|
|
|
Suppression *s;
|
|
|
|
// Match "odr_violation" suppressions.
|
|
|
|
return suppression_ctx->Match(global_var_name, kODRViolation, &s);
|
|
|
|
}
|
|
|
|
|
2014-12-06 04:26:09 +08:00
|
|
|
bool IsStackTraceSuppressed(const StackTrace *stack) {
|
|
|
|
if (!HaveStackTraceBasedSuppressions())
|
|
|
|
return false;
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
CHECK(suppression_ctx);
|
2014-12-06 04:26:09 +08:00
|
|
|
Symbolizer *symbolizer = Symbolizer::GetOrInit();
|
|
|
|
Suppression *s;
|
|
|
|
for (uptr i = 0; i < stack->size && stack->trace[i]; i++) {
|
|
|
|
uptr addr = stack->trace[i];
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
if (suppression_ctx->HasSuppressionType(kInterceptorViaLibrary)) {
|
2014-12-06 04:26:09 +08:00
|
|
|
// Match "interceptor_via_lib" suppressions.
|
2015-03-05 09:30:36 +08:00
|
|
|
if (const char *module_name = symbolizer->GetModuleNameForPc(addr))
|
|
|
|
if (suppression_ctx->Match(module_name, kInterceptorViaLibrary, &s))
|
|
|
|
return true;
|
2014-12-06 04:26:09 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 01:41:59 +08:00
|
|
|
if (suppression_ctx->HasSuppressionType(kInterceptorViaFunction)) {
|
2014-12-06 04:26:09 +08:00
|
|
|
SymbolizedStack *frames = symbolizer->SymbolizePC(addr);
|
2016-05-03 03:07:20 +08:00
|
|
|
CHECK(frames);
|
2014-12-06 04:26:09 +08:00
|
|
|
for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
|
|
|
|
const char *function_name = cur->info.function;
|
|
|
|
if (!function_name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Match "interceptor_via_fun" suppressions.
|
2015-02-21 01:41:59 +08:00
|
|
|
if (suppression_ctx->Match(function_name, kInterceptorViaFunction,
|
|
|
|
&s)) {
|
2014-12-06 04:26:09 +08:00
|
|
|
frames->ClearAll();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frames->ClearAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __asan
|