Revert "Add SetLastChanceExceptionHandler to implement permissive MTE mode"

This reverts commit b1e66e322ddd07f4640ee8bad93397a0511cd313.

Reason for revert: test was flaky on Android bot

Original change's description:
> Add SetLastChanceExceptionHandler to implement permissive MTE mode
>
> SetLastChanceExceptionHandler sets a callback to be called after a
> crash has been reported. Returning true from this callback will
> not reraise the signal so the execution can continue. This will be
> used to implement permissive MTE mode, which will continue execution
> after a MTE crash.
>
> Bug: chromium:1467915
> Change-Id: I93a28ceea921fe977805482cf47c07643ca6133c
> Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4707688
> Reviewed-by: Robert Sesek <rsesek@chromium.org>
> Commit-Queue: Keishi Hattori <keishi@chromium.org>

Bug: chromium:1467915
Change-Id: Id815a780b576088974101117a4587adec64cfe8c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4750459
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
This commit is contained in:
Keishi Hattori 2023-08-03 19:10:49 +00:00 committed by Crashpad LUCI CQ
parent b1e66e322d
commit ce7f0f1de9
3 changed files with 3 additions and 72 deletions

View File

@ -456,24 +456,6 @@ class CrashpadClient {
//! \param[in] handler The custom crash signal handler to install. //! \param[in] handler The custom crash signal handler to install.
static void SetFirstChanceExceptionHandler(FirstChanceHandler handler); static void SetFirstChanceExceptionHandler(FirstChanceHandler handler);
//! \brief Installs a custom crash signal handler which runs after the
//! currently installed Crashpad handler.
//!
//! Handling signals appropriately can be tricky and use of this method
//! should be avoided, if possible.
//!
//! A handler must have already been installed before calling this method.
//!
//! The custom handler runs in a signal handler context and must be safe for
//! that purpose.
//!
//! If the custom handler returns `true`, the signal is not reraised.
//!
//! \param[in] handler The custom crash signal handler to install.
static void SetLastChanceExceptionHandler(bool (*handler)(int,
siginfo_t*,
ucontext_t*));
//! \brief Configures a set of signals that shouldn't have Crashpad signal //! \brief Configures a set of signals that shouldn't have Crashpad signal
//! handlers installed. //! handlers installed.
//! //!

View File

@ -131,8 +131,6 @@ std::vector<std::string> BuildArgsToLaunchWithLinker(
#endif // BUILDFLAG(IS_ANDROID) #endif // BUILDFLAG(IS_ANDROID)
using LastChanceHandler = bool (*)(int, siginfo_t*, ucontext_t*);
// A base class for Crashpad signal handler implementations. // A base class for Crashpad signal handler implementations.
class SignalHandler { class SignalHandler {
public: public:
@ -156,10 +154,6 @@ class SignalHandler {
first_chance_handler_ = handler; first_chance_handler_ = handler;
} }
void SetLastChanceExceptionHandler(LastChanceHandler handler) {
last_chance_handler_ = handler;
}
// The base implementation for all signal handlers, suitable for calling // The base implementation for all signal handlers, suitable for calling
// directly to simulate signal delivery. // directly to simulate signal delivery.
void HandleCrash(int signo, siginfo_t* siginfo, void* context) { void HandleCrash(int signo, siginfo_t* siginfo, void* context) {
@ -218,11 +212,6 @@ class SignalHandler {
if (!handler_->disabled_.test_and_set()) { if (!handler_->disabled_.test_and_set()) {
handler_->HandleCrash(signo, siginfo, context); handler_->HandleCrash(signo, siginfo, context);
handler_->WakeThreads(); handler_->WakeThreads();
if (handler_->last_chance_handler_ &&
handler_->last_chance_handler_(
signo, siginfo, static_cast<ucontext_t*>(context))) {
return;
}
} else { } else {
// Processes on Android normally have several chained signal handlers that // Processes on Android normally have several chained signal handlers that
// co-operate to report crashes. e.g. WebView will have this signal // co-operate to report crashes. e.g. WebView will have this signal
@ -265,7 +254,6 @@ class SignalHandler {
Signals::OldActions old_actions_ = {}; Signals::OldActions old_actions_ = {};
ExceptionInformation exception_information_ = {}; ExceptionInformation exception_information_ = {};
CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr; CrashpadClient::FirstChanceHandler first_chance_handler_ = nullptr;
LastChanceHandler last_chance_handler_ = nullptr;
int32_t dump_done_futex_ = kDumpNotDone; int32_t dump_done_futex_ = kDumpNotDone;
#if !defined(__cpp_lib_atomic_value_initialization) || \ #if !defined(__cpp_lib_atomic_value_initialization) || \
__cpp_lib_atomic_value_initialization < 201911L __cpp_lib_atomic_value_initialization < 201911L
@ -751,12 +739,6 @@ void CrashpadClient::SetFirstChanceExceptionHandler(
SignalHandler::Get()->SetFirstChanceHandler(handler); SignalHandler::Get()->SetFirstChanceHandler(handler);
} }
// static
void CrashpadClient::SetLastChanceExceptionHandler(LastChanceHandler handler) {
DCHECK(SignalHandler::Get());
SignalHandler::Get()->SetLastChanceExceptionHandler(handler);
}
void CrashpadClient::SetUnhandledSignals(const std::set<int>& signals) { void CrashpadClient::SetUnhandledSignals(const std::set<int>& signals) {
DCHECK(!SignalHandler::Get()); DCHECK(!SignalHandler::Get());
unhandled_signals_ = signals; unhandled_signals_ = signals;

View File

@ -71,14 +71,11 @@ enum class CrashType : uint32_t {
kBuiltinTrap, kBuiltinTrap,
kInfiniteRecursion, kInfiniteRecursion,
kSegvWithTagBits, kSegvWithTagBits,
// kFakeSegv is meant to simulate a MTE segv error.
kFakeSegv,
}; };
struct StartHandlerForSelfTestOptions { struct StartHandlerForSelfTestOptions {
bool start_handler_at_crash; bool start_handler_at_crash;
bool set_first_chance_handler; bool set_first_chance_handler;
bool set_last_chance_handler;
bool crash_non_main_thread; bool crash_non_main_thread;
bool client_uses_signals; bool client_uses_signals;
bool gather_indirectly_referenced_memory; bool gather_indirectly_referenced_memory;
@ -87,7 +84,7 @@ struct StartHandlerForSelfTestOptions {
class StartHandlerForSelfTest class StartHandlerForSelfTest
: public testing::TestWithParam< : public testing::TestWithParam<
std::tuple<bool, bool, bool, bool, bool, bool, CrashType>> { std::tuple<bool, bool, bool, bool, bool, CrashType>> {
public: public:
StartHandlerForSelfTest() = default; StartHandlerForSelfTest() = default;
@ -102,7 +99,6 @@ class StartHandlerForSelfTest
memset(&options_, 0, sizeof(options_)); memset(&options_, 0, sizeof(options_));
std::tie(options_.start_handler_at_crash, std::tie(options_.start_handler_at_crash,
options_.set_first_chance_handler, options_.set_first_chance_handler,
options_.set_last_chance_handler,
options_.crash_non_main_thread, options_.crash_non_main_thread,
options_.client_uses_signals, options_.client_uses_signals,
options_.gather_indirectly_referenced_memory, options_.gather_indirectly_referenced_memory,
@ -248,10 +244,6 @@ bool HandleCrashSuccessfully(int, siginfo_t*, ucontext_t*) {
#pragma clang diagnostic pop #pragma clang diagnostic pop
} }
bool HandleCrashSuccessfullyAfterReporting(int, siginfo_t*, ucontext_t*) {
return true;
}
void DoCrash(const StartHandlerForSelfTestOptions& options, void DoCrash(const StartHandlerForSelfTestOptions& options,
CrashpadClient* client) { CrashpadClient* client) {
if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) { if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) {
@ -281,11 +273,6 @@ void DoCrash(const StartHandlerForSelfTestOptions& options,
*x; *x;
break; break;
} }
case CrashType::kFakeSegv: {
raise(SIGSEGV);
break;
}
} }
} }
@ -416,10 +403,6 @@ CRASHPAD_CHILD_TEST_MAIN(StartHandlerForSelfTestChild) {
client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully); client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully);
} }
if (options.set_last_chance_handler) {
client.SetLastChanceExceptionHandler(HandleCrashSuccessfullyAfterReporting);
}
#if BUILDFLAG(IS_ANDROID) #if BUILDFLAG(IS_ANDROID)
if (android_set_abort_message) { if (android_set_abort_message) {
android_set_abort_message(kTestAbortMessage); android_set_abort_message(kTestAbortMessage);
@ -457,16 +440,6 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec {
case CrashType::kSegvWithTagBits: case CrashType::kSegvWithTagBits:
SetExpectedChildTermination(TerminationReason::kTerminationSignal, SetExpectedChildTermination(TerminationReason::kTerminationSignal,
SIGSEGV); SIGSEGV);
break;
case CrashType::kFakeSegv:
if (!options.set_last_chance_handler) {
SetExpectedChildTermination(TerminationReason::kTerminationSignal,
SIGSEGV);
} else {
SetExpectedChildTermination(TerminationReason::kTerminationNormal,
EXIT_SUCCESS);
}
break;
} }
} }
} }
@ -498,11 +471,7 @@ class StartHandlerForSelfInChildTest : public MultiprocessExec {
writer.Close(); writer.Close();
if (options_.client_uses_signals && !options_.set_first_chance_handler && if (options_.client_uses_signals && !options_.set_first_chance_handler &&
options_.crash_type != CrashType::kSimulated && options_.crash_type != CrashType::kSimulated) {
// The last chance handler will prevent the client handler from being
// called if crash type is kFakeSegv.
(!options_.set_last_chance_handler ||
options_.crash_type != CrashType::kFakeSegv)) {
// Wait for child's client signal handler. // Wait for child's client signal handler.
char c; char c;
EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c))); EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c)));
@ -580,12 +549,10 @@ INSTANTIATE_TEST_SUITE_P(
testing::Bool(), testing::Bool(),
testing::Bool(), testing::Bool(),
testing::Bool(), testing::Bool(),
testing::Bool(),
testing::Values(CrashType::kSimulated, testing::Values(CrashType::kSimulated,
CrashType::kBuiltinTrap, CrashType::kBuiltinTrap,
CrashType::kInfiniteRecursion, CrashType::kInfiniteRecursion,
CrashType::kSegvWithTagBits, CrashType::kSegvWithTagBits)));
CrashType::kFakeSegv)));
// Test state for starting the handler for another process. // Test state for starting the handler for another process.
class StartHandlerForClientTest { class StartHandlerForClientTest {