-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[rtsan] Support basic call stack suppressions #111608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19b53fe
[rtsan] Support suppressions list
cjappl 36880be
[PR] fmayer - null char, make scope of symbolizer smaller
cjappl 17d99d6
[PR] fmayer - fix location of symbolizer init
cjappl 888b53d
[PR] dtraev/fmayer - call-stack-contains, small refactor of nullptr c…
cjappl 87b29f0
[PR] vitalybuka - revert 'HasSuppressions' function
cjappl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- rtsan_checks.inc ----------------------------------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// List of suppression checks handled by RTSan runtime. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef RTSAN_CHECK | ||
#error "Define RTSAN_CHECK prior to including this file!" | ||
#endif | ||
|
||
// RTSAN_CHECK(Name, SummaryKind) | ||
// SummaryKind should be a string literal. | ||
|
||
RTSAN_CHECK(CallStackContains, "call-stack-contains") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//===--- rtsan_suppressions.cpp - Realtime Sanitizer ------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of the RTSan runtime, providing support for suppressions | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "rtsan/rtsan_suppressions.h" | ||
|
||
#include "rtsan/rtsan_flags.h" | ||
|
||
#include "sanitizer_common/sanitizer_common.h" | ||
#include "sanitizer_common/sanitizer_internal_defs.h" | ||
#include "sanitizer_common/sanitizer_suppressions.h" | ||
#include "sanitizer_common/sanitizer_symbolizer.h" | ||
|
||
#include <new> | ||
|
||
using namespace __sanitizer; | ||
using namespace __rtsan; | ||
|
||
namespace { | ||
enum class ErrorType { | ||
#define RTSAN_CHECK(Name, FSanitizeFlagName) Name, | ||
#include "rtsan_checks.inc" | ||
#undef RTSAN_CHECK | ||
}; | ||
} // namespace | ||
|
||
alignas(64) static char suppression_placeholder[sizeof(SuppressionContext)]; | ||
static SuppressionContext *suppression_ctx = nullptr; | ||
|
||
static const char *kSuppressionTypes[] = { | ||
#define RTSAN_CHECK(Name, FSanitizeFlagName) FSanitizeFlagName, | ||
#include "rtsan_checks.inc" | ||
#undef RTSAN_CHECK | ||
}; | ||
|
||
static const char *ConvertTypeToFlagName(ErrorType Type) { | ||
switch (Type) { | ||
#define RTSAN_CHECK(Name, FSanitizeFlagName) \ | ||
case ErrorType::Name: \ | ||
return FSanitizeFlagName; | ||
#include "rtsan_checks.inc" | ||
#undef RTSAN_CHECK | ||
} | ||
UNREACHABLE("unknown ErrorType!"); | ||
} | ||
|
||
void __rtsan::InitializeSuppressions() { | ||
CHECK_EQ(nullptr, suppression_ctx); | ||
|
||
// We will use suppression_ctx == nullptr as an early out | ||
if (flags().suppressions[0] == '\0') | ||
return; | ||
|
||
suppression_ctx = new (suppression_placeholder) | ||
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes)); | ||
suppression_ctx->ParseFromFile(flags().suppressions); | ||
} | ||
|
||
bool __rtsan::IsStackTraceSuppressed(const StackTrace &stack) { | ||
if (suppression_ctx == nullptr) | ||
cjappl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
|
||
const char *call_stack_flag = | ||
ConvertTypeToFlagName(ErrorType::CallStackContains); | ||
if (!suppression_ctx->HasSuppressionType(call_stack_flag)) | ||
return false; | ||
|
||
Symbolizer *symbolizer = Symbolizer::GetOrInit(); | ||
for (uptr i = 0; i < stack.size && stack.trace[i]; i++) { | ||
const uptr addr = stack.trace[i]; | ||
|
||
SymbolizedStackHolder symbolized_stack(symbolizer->SymbolizePC(addr)); | ||
const SymbolizedStack *frames = symbolized_stack.get(); | ||
CHECK(frames); | ||
for (const SymbolizedStack *cur = frames; cur; cur = cur->next) { | ||
const char *function_name = cur->info.function; | ||
if (!function_name) | ||
continue; | ||
|
||
Suppression *s; | ||
if (suppression_ctx->Match(function_name, call_stack_flag, &s)) | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===--- rtsan_suppressions.h - Realtime Sanitizer --------------*- C++ -*-===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file is a part of the RTSan runtime, providing support for suppressions | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "sanitizer_common/sanitizer_stacktrace.h" | ||
|
||
namespace __rtsan { | ||
|
||
void InitializeSuppressions(); | ||
bool IsStackTraceSuppressed(const __sanitizer::StackTrace &stack); | ||
|
||
} // namespace __rtsan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// RUN: %clangxx -fsanitize=realtime %s -o %t | ||
// RUN: %env_rtsan_opts=suppressions='%s.supp' not %run %t 2>&1 | FileCheck %s | ||
// UNSUPPORTED: ios | ||
|
||
// Intent: Ensure that suppressions work as intended | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include <vector> | ||
|
||
void *MallocViolation() { return malloc(10); } | ||
|
||
void VectorViolations() { | ||
// All of these should be suppressed by *vector* | ||
std::vector<int> v(10); | ||
v.resize(20); | ||
v.clear(); | ||
v.resize(0); | ||
v.push_back(1); | ||
v.reserve(10); | ||
} | ||
|
||
void BlockFunc() [[clang::blocking]] { usleep(1); } | ||
|
||
void *process() [[clang::nonblocking]] { | ||
void *ptr = MallocViolation(); | ||
VectorViolations(); | ||
BlockFunc(); | ||
free(ptr); | ||
|
||
// This is the one that should abort the program | ||
// Everything else is suppressed | ||
usleep(1); | ||
|
||
return ptr; | ||
} | ||
|
||
int main() { | ||
process(); | ||
return 0; | ||
} | ||
|
||
// CHECK-NOT: failed to open suppressions file | ||
// CHECK: Intercepted call to real-time unsafe function | ||
// CHECK-SAME: usleep | ||
|
||
// CHECK-NOT: Intercepted call to real-time unsafe function | ||
// CHECK-NOT: malloc | ||
// CHECK-NOT: vector | ||
// CHECK-NOT: free | ||
// CHECK-NOT: BlockFunc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
call-stack-contains:MallocViolation | ||
call-stack-contains:std::*vector | ||
call-stack-contains:free | ||
call-stack-contains:BlockFunc |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.