2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2018 The Crashpad Authors
|
2018-02-22 13:29:05 -08:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "client/crashpad_client.h"
|
|
|
|
|
2019-03-29 15:22:11 -07:00
|
|
|
#include <dlfcn.h>
|
2022-01-20 08:57:13 -08:00
|
|
|
#include <setjmp.h>
|
2020-07-15 11:26:08 -07:00
|
|
|
#include <signal.h>
|
2018-02-22 13:29:05 -08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
#include <sys/utsname.h>
|
2018-02-22 13:29:05 -08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2020-06-22 11:14:31 +02:00
|
|
|
#include "base/check_op.h"
|
|
|
|
#include "base/notreached.h"
|
2022-01-19 15:00:24 -05:00
|
|
|
#include "build/build_config.h"
|
2018-05-10 17:15:59 -07:00
|
|
|
#include "client/annotation.h"
|
|
|
|
#include "client/annotation_list.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "client/crash_report_database.h"
|
2021-12-13 13:48:45 -08:00
|
|
|
#include "client/crashpad_info.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "client/simulate_crash.h"
|
|
|
|
#include "gtest/gtest.h"
|
2018-05-10 17:15:59 -07:00
|
|
|
#include "snapshot/annotation_snapshot.h"
|
|
|
|
#include "snapshot/minidump/process_snapshot_minidump.h"
|
2018-06-12 08:30:36 -07:00
|
|
|
#include "snapshot/sanitized/sanitization_information.h"
|
2020-07-15 11:26:08 -07:00
|
|
|
#include "test/errors.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "test/multiprocess.h"
|
2018-05-10 17:15:59 -07:00
|
|
|
#include "test/multiprocess_exec.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "test/scoped_temp_dir.h"
|
|
|
|
#include "test/test_paths.h"
|
|
|
|
#include "util/file/file_io.h"
|
2018-05-10 17:15:59 -07:00
|
|
|
#include "util/file/filesystem.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "util/linux/exception_handler_client.h"
|
|
|
|
#include "util/linux/exception_information.h"
|
2019-05-02 13:55:08 -07:00
|
|
|
#include "util/linux/socket.h"
|
2020-07-20 13:29:44 -07:00
|
|
|
#include "util/misc/address_sanitizer.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "util/misc/address_types.h"
|
|
|
|
#include "util/misc/from_pointer_cast.h"
|
2020-07-21 09:31:16 -07:00
|
|
|
#include "util/misc/memory_sanitizer.h"
|
2020-07-15 11:26:08 -07:00
|
|
|
#include "util/posix/scoped_mmap.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
#include "util/posix/signals.h"
|
2020-07-15 11:26:08 -07:00
|
|
|
#include "util/thread/thread.h"
|
2018-02-22 13:29:05 -08:00
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2019-03-29 15:22:11 -07:00
|
|
|
#include <android/set_abort_message.h>
|
|
|
|
#include "dlfcn_internal.h"
|
|
|
|
|
|
|
|
// Normally this comes from set_abort_message.h, but only at API level 21.
|
|
|
|
extern "C" void android_set_abort_message(const char* msg)
|
|
|
|
__attribute__((weak));
|
|
|
|
#endif
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
|
|
|
namespace {
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
enum class CrashType : uint32_t {
|
|
|
|
kSimulated,
|
|
|
|
kBuiltinTrap,
|
|
|
|
kInfiniteRecursion,
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
kSegvWithTagBits,
|
2023-08-31 17:27:07 +00:00
|
|
|
// kFakeSegv is meant to simulate a MTE segv error.
|
|
|
|
kFakeSegv,
|
2020-07-15 11:26:08 -07:00
|
|
|
};
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
struct StartHandlerForSelfTestOptions {
|
|
|
|
bool start_handler_at_crash;
|
|
|
|
bool set_first_chance_handler;
|
2023-08-31 17:27:07 +00:00
|
|
|
bool set_last_chance_handler;
|
2020-07-15 11:26:08 -07:00
|
|
|
bool crash_non_main_thread;
|
|
|
|
bool client_uses_signals;
|
2021-12-13 13:48:45 -08:00
|
|
|
bool gather_indirectly_referenced_memory;
|
2020-07-15 11:26:08 -07:00
|
|
|
CrashType crash_type;
|
2019-05-01 22:19:21 -07:00
|
|
|
};
|
2018-02-23 11:32:06 -08:00
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
class StartHandlerForSelfTest
|
2020-07-15 11:26:08 -07:00
|
|
|
: public testing::TestWithParam<
|
2023-08-31 17:27:07 +00:00
|
|
|
std::tuple<bool, bool, bool, bool, bool, bool, CrashType>> {
|
2019-05-01 22:19:21 -07:00
|
|
|
public:
|
|
|
|
StartHandlerForSelfTest() = default;
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
StartHandlerForSelfTest(const StartHandlerForSelfTest&) = delete;
|
|
|
|
StartHandlerForSelfTest& operator=(const StartHandlerForSelfTest&) = delete;
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
~StartHandlerForSelfTest() = default;
|
2018-02-23 11:32:06 -08:00
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
void SetUp() override {
|
2021-12-20 12:57:44 -08:00
|
|
|
// MSAN requires that padding bytes have been initialized for structs that
|
|
|
|
// are written to files.
|
|
|
|
memset(&options_, 0, sizeof(options_));
|
2019-05-01 22:19:21 -07:00
|
|
|
std::tie(options_.start_handler_at_crash,
|
2020-07-15 11:26:08 -07:00
|
|
|
options_.set_first_chance_handler,
|
2023-08-31 17:27:07 +00:00
|
|
|
options_.set_last_chance_handler,
|
2020-07-15 11:26:08 -07:00
|
|
|
options_.crash_non_main_thread,
|
|
|
|
options_.client_uses_signals,
|
2021-12-13 13:48:45 -08:00
|
|
|
options_.gather_indirectly_referenced_memory,
|
2020-07-15 11:26:08 -07:00
|
|
|
options_.crash_type) = GetParam();
|
2018-02-23 11:32:06 -08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
const StartHandlerForSelfTestOptions& Options() const { return options_; }
|
2018-02-23 11:32:06 -08:00
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
private:
|
|
|
|
StartHandlerForSelfTestOptions options_;
|
|
|
|
};
|
2018-02-22 13:29:05 -08:00
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
bool InstallHandler(CrashpadClient* client,
|
|
|
|
bool start_at_crash,
|
|
|
|
const base::FilePath& handler_path,
|
2020-06-24 09:03:47 +02:00
|
|
|
const base::FilePath& database_path,
|
|
|
|
const std::vector<base::FilePath>& attachments) {
|
2019-05-01 22:19:21 -07:00
|
|
|
return start_at_crash
|
|
|
|
? client->StartHandlerAtCrash(handler_path,
|
|
|
|
database_path,
|
|
|
|
base::FilePath(),
|
|
|
|
"",
|
|
|
|
std::map<std::string, std::string>(),
|
2020-06-24 09:03:47 +02:00
|
|
|
std::vector<std::string>(),
|
|
|
|
attachments)
|
2019-05-01 22:19:21 -07:00
|
|
|
: client->StartHandler(handler_path,
|
|
|
|
database_path,
|
|
|
|
base::FilePath(),
|
|
|
|
"",
|
|
|
|
std::map<std::string, std::string>(),
|
|
|
|
std::vector<std::string>(),
|
|
|
|
false,
|
2020-06-24 09:03:47 +02:00
|
|
|
false,
|
|
|
|
attachments);
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
2018-05-10 17:15:59 -07:00
|
|
|
constexpr char kTestAnnotationName[] = "name_of_annotation";
|
|
|
|
constexpr char kTestAnnotationValue[] = "value_of_annotation";
|
2020-06-24 09:03:47 +02:00
|
|
|
constexpr char kTestAttachmentName[] = "test_attachment";
|
|
|
|
constexpr char kTestAttachmentContent[] = "attachment_content";
|
2018-05-10 17:15:59 -07:00
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2019-03-29 15:22:11 -07:00
|
|
|
constexpr char kTestAbortMessage[] = "test abort message";
|
|
|
|
#endif
|
|
|
|
|
2020-06-24 09:03:47 +02:00
|
|
|
void ValidateAttachment(const CrashReportDatabase::UploadReport* report) {
|
|
|
|
auto attachments = report->GetAttachments();
|
|
|
|
ASSERT_EQ(attachments.size(), 1u);
|
|
|
|
char buf[sizeof(kTestAttachmentContent)];
|
|
|
|
attachments.at(kTestAttachmentName)->Read(buf, sizeof(buf));
|
|
|
|
ASSERT_EQ(memcmp(kTestAttachmentContent, buf, sizeof(kTestAttachmentContent)),
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2021-12-13 13:48:45 -08:00
|
|
|
void ValidateExtraMemory(const StartHandlerForSelfTestOptions& options,
|
|
|
|
const ProcessSnapshotMinidump& minidump) {
|
2021-11-12 23:22:38 +01:00
|
|
|
// Verify that if we have an exception, then the code around the instruction
|
|
|
|
// pointer is included in the extra memory.
|
|
|
|
const ExceptionSnapshot* exception = minidump.Exception();
|
|
|
|
if (exception == nullptr)
|
|
|
|
return;
|
|
|
|
uint64_t pc = exception->Context()->InstructionPointer();
|
|
|
|
std::vector<const MemorySnapshot*> snippets = minidump.ExtraMemory();
|
|
|
|
bool pc_found = false;
|
|
|
|
for (const MemorySnapshot* snippet : snippets) {
|
|
|
|
uint64_t start = snippet->Address();
|
|
|
|
uint64_t end = start + snippet->Size();
|
|
|
|
if (pc >= start && pc < end) {
|
|
|
|
pc_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-13 13:48:45 -08:00
|
|
|
EXPECT_EQ(pc_found, options.gather_indirectly_referenced_memory);
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
|
|
|
|
if (options.crash_type == CrashType::kSegvWithTagBits) {
|
|
|
|
EXPECT_EQ(exception->ExceptionAddress(), 0xefull << 56);
|
|
|
|
}
|
2021-11-12 23:22:38 +01:00
|
|
|
}
|
|
|
|
|
2021-12-13 13:48:45 -08:00
|
|
|
void ValidateDump(const StartHandlerForSelfTestOptions& options,
|
|
|
|
const CrashReportDatabase::UploadReport* report) {
|
2018-05-10 17:15:59 -07:00
|
|
|
ProcessSnapshotMinidump minidump_snapshot;
|
|
|
|
ASSERT_TRUE(minidump_snapshot.Initialize(report->Reader()));
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2019-03-29 15:22:11 -07:00
|
|
|
// This part of the test requires Q. The API level on Q devices will be 28
|
|
|
|
// until the API is finalized, so we can't check API level yet. For now, test
|
|
|
|
// for the presence of a libc symbol which was introduced in Q.
|
|
|
|
if (crashpad::internal::Dlsym(RTLD_DEFAULT, "android_fdsan_close_with_tag")) {
|
|
|
|
const auto& annotations = minidump_snapshot.AnnotationsSimpleMap();
|
|
|
|
auto abort_message = annotations.find("abort_message");
|
|
|
|
ASSERT_NE(annotations.end(), abort_message);
|
|
|
|
EXPECT_EQ(kTestAbortMessage, abort_message->second);
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-24 09:03:47 +02:00
|
|
|
ValidateAttachment(report);
|
2019-03-29 15:22:11 -07:00
|
|
|
|
2021-12-13 13:48:45 -08:00
|
|
|
ValidateExtraMemory(options, minidump_snapshot);
|
2021-11-12 23:22:38 +01:00
|
|
|
|
2018-05-10 17:15:59 -07:00
|
|
|
for (const ModuleSnapshot* module : minidump_snapshot.Modules()) {
|
|
|
|
for (const AnnotationSnapshot& annotation : module->AnnotationObjects()) {
|
|
|
|
if (static_cast<Annotation::Type>(annotation.type) !=
|
|
|
|
Annotation::Type::kString) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (annotation.name == kTestAnnotationName) {
|
|
|
|
std::string value(
|
|
|
|
reinterpret_cast<const char*>(annotation.value.data()),
|
|
|
|
annotation.value.size());
|
|
|
|
EXPECT_EQ(value, kTestAnnotationValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ADD_FAILURE();
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winfinite-recursion"
|
2022-11-10 19:39:08 +01:00
|
|
|
// Clang (masquerading as gcc) is too smart, and removes the recursion
|
|
|
|
// otherwise. May need to change if either clang or another compiler becomes
|
|
|
|
// smarter.
|
|
|
|
#if defined(COMPILER_GCC)
|
|
|
|
__attribute__((noinline))
|
|
|
|
#endif
|
2023-04-21 13:26:17 -04:00
|
|
|
#if defined(__clang__)
|
|
|
|
__attribute__((optnone))
|
|
|
|
#endif
|
2020-07-15 11:26:08 -07:00
|
|
|
int RecurseInfinitely(int* ptr) {
|
|
|
|
int buf[1 << 20];
|
|
|
|
return *ptr + RecurseInfinitely(buf);
|
|
|
|
}
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
|
2022-01-20 08:57:13 -08:00
|
|
|
sigjmp_buf do_crash_sigjmp_env;
|
|
|
|
|
|
|
|
bool HandleCrashSuccessfully(int, siginfo_t*, ucontext_t*) {
|
|
|
|
siglongjmp(do_crash_sigjmp_env, 1);
|
2022-01-20 11:36:38 -08:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wunreachable-code-return"
|
2022-01-20 08:57:13 -08:00
|
|
|
return true;
|
2022-01-20 11:36:38 -08:00
|
|
|
#pragma clang diagnostic pop
|
2022-01-20 08:57:13 -08:00
|
|
|
}
|
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
bool HandleCrashSuccessfullyAfterReporting(int, siginfo_t*, ucontext_t*) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
void DoCrash(const StartHandlerForSelfTestOptions& options,
|
|
|
|
CrashpadClient* client) {
|
2022-01-20 08:57:13 -08:00
|
|
|
if (sigsetjmp(do_crash_sigjmp_env, 1) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
switch (options.crash_type) {
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
case CrashType::kSimulated: {
|
2020-07-15 11:26:08 -07:00
|
|
|
CRASHPAD_SIMULATE_CRASH();
|
|
|
|
break;
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
}
|
2020-07-15 11:26:08 -07:00
|
|
|
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
case CrashType::kBuiltinTrap: {
|
2020-07-15 11:26:08 -07:00
|
|
|
__builtin_trap();
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
}
|
2020-07-15 11:26:08 -07:00
|
|
|
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
case CrashType::kInfiniteRecursion: {
|
2020-07-15 11:26:08 -07:00
|
|
|
int val = 42;
|
|
|
|
exit(RecurseInfinitely(&val));
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
case CrashType::kSegvWithTagBits: {
|
|
|
|
volatile char* x = nullptr;
|
|
|
|
#ifdef __aarch64__
|
|
|
|
x += 0xefull << 56;
|
|
|
|
#endif // __aarch64__
|
|
|
|
*x;
|
|
|
|
break;
|
|
|
|
}
|
2023-08-31 17:27:07 +00:00
|
|
|
|
|
|
|
case CrashType::kFakeSegv: {
|
|
|
|
// With a regular SIGSEGV like null dereference, the signal gets reraised
|
|
|
|
// automatically, causing HandleOrReraiseSignal() to be called a second
|
|
|
|
// time, terminating the process with the signal regardless of the last
|
|
|
|
// chance handler.
|
|
|
|
raise(SIGSEGV);
|
|
|
|
break;
|
|
|
|
}
|
2020-07-15 11:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ScopedAltSignalStack {
|
|
|
|
public:
|
|
|
|
ScopedAltSignalStack() = default;
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
ScopedAltSignalStack(const ScopedAltSignalStack&) = delete;
|
|
|
|
ScopedAltSignalStack& operator=(const ScopedAltSignalStack&) = delete;
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
~ScopedAltSignalStack() {
|
|
|
|
if (stack_mem_.is_valid()) {
|
|
|
|
stack_t stack;
|
|
|
|
stack.ss_flags = SS_DISABLE;
|
|
|
|
if (sigaltstack(&stack, nullptr) != 0) {
|
|
|
|
ADD_FAILURE() << ErrnoMessage("sigaltstack");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Initialize() {
|
|
|
|
ScopedMmap local_stack_mem;
|
2022-11-10 19:01:53 +01:00
|
|
|
const size_t stack_size = MINSIGSTKSZ;
|
2020-07-15 11:26:08 -07:00
|
|
|
ASSERT_TRUE(local_stack_mem.ResetMmap(nullptr,
|
|
|
|
stack_size,
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS,
|
|
|
|
-1,
|
|
|
|
0));
|
|
|
|
|
|
|
|
stack_t stack;
|
|
|
|
stack.ss_sp = local_stack_mem.addr();
|
|
|
|
stack.ss_size = stack_size;
|
|
|
|
stack.ss_flags = 0;
|
|
|
|
ASSERT_EQ(sigaltstack(&stack, nullptr), 0) << ErrnoMessage("sigaltstack");
|
|
|
|
stack_mem_.ResetAddrLen(local_stack_mem.release(), stack_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ScopedMmap stack_mem_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CrashThread : public Thread {
|
|
|
|
public:
|
|
|
|
CrashThread(const StartHandlerForSelfTestOptions& options,
|
|
|
|
CrashpadClient* client)
|
|
|
|
: client_signal_stack_(), options_(options), client_(client) {}
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
CrashThread(const CrashThread&) = delete;
|
|
|
|
CrashThread& operator=(const CrashThread&) = delete;
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
private:
|
|
|
|
void ThreadMain() override {
|
|
|
|
// It is only necessary to call InitializeSignalStackForThread() once, but
|
|
|
|
// should be harmless to call multiple times and durable against the client
|
|
|
|
// using sigaltstack() either before or after it is called.
|
|
|
|
CrashpadClient::InitializeSignalStackForThread();
|
|
|
|
if (options_.client_uses_signals) {
|
|
|
|
client_signal_stack_.Initialize();
|
|
|
|
}
|
|
|
|
CrashpadClient::InitializeSignalStackForThread();
|
|
|
|
|
|
|
|
DoCrash(options_, client_);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedAltSignalStack client_signal_stack_;
|
|
|
|
const StartHandlerForSelfTestOptions& options_;
|
|
|
|
CrashpadClient* client_;
|
|
|
|
};
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
CRASHPAD_CHILD_TEST_MAIN(StartHandlerForSelfTestChild) {
|
2018-02-22 13:29:05 -08:00
|
|
|
FileHandle in = StdioFileHandle(StdioStream::kStandardInput);
|
|
|
|
|
|
|
|
VMSize temp_dir_length;
|
|
|
|
CheckedReadFileExactly(in, &temp_dir_length, sizeof(temp_dir_length));
|
|
|
|
|
|
|
|
std::string temp_dir(temp_dir_length, '\0');
|
|
|
|
CheckedReadFileExactly(in, &temp_dir[0], temp_dir_length);
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
StartHandlerForSelfTestOptions options;
|
|
|
|
CheckedReadFileExactly(in, &options, sizeof(options));
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
ScopedAltSignalStack client_signal_stack;
|
|
|
|
if (options.client_uses_signals) {
|
|
|
|
client_signal_stack.Initialize();
|
|
|
|
|
|
|
|
static Signals::OldActions old_actions;
|
|
|
|
static Signals::Handler client_handler =
|
|
|
|
[](int signo, siginfo_t* siginfo, void*) {
|
|
|
|
FileHandle out = StdioFileHandle(StdioStream::kStandardOutput);
|
2020-07-21 09:31:16 -07:00
|
|
|
char c = 0;
|
2020-07-15 11:26:08 -07:00
|
|
|
WriteFile(out, &c, sizeof(c));
|
|
|
|
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(
|
|
|
|
siginfo, old_actions.ActionForSignal(signo));
|
|
|
|
};
|
|
|
|
|
|
|
|
CHECK(Signals::InstallCrashHandlers(
|
|
|
|
client_handler, SA_ONSTACK, &old_actions));
|
|
|
|
}
|
|
|
|
|
2021-12-13 13:48:45 -08:00
|
|
|
if (options.gather_indirectly_referenced_memory) {
|
|
|
|
CrashpadInfo::GetCrashpadInfo()->set_gather_indirectly_referenced_memory(
|
|
|
|
TriState::kEnabled, 1024 * 1024 * 4);
|
|
|
|
}
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
base::FilePath handler_path = TestPaths::Executable().DirName().Append(
|
|
|
|
FILE_PATH_LITERAL("crashpad_handler"));
|
|
|
|
|
2018-05-10 17:15:59 -07:00
|
|
|
crashpad::AnnotationList::Register();
|
|
|
|
|
|
|
|
static StringAnnotation<32> test_annotation(kTestAnnotationName);
|
|
|
|
test_annotation.Set(kTestAnnotationValue);
|
|
|
|
|
2020-06-24 09:03:47 +02:00
|
|
|
const std::vector<base::FilePath> attachments = {
|
2020-07-16 11:30:21 -07:00
|
|
|
base::FilePath(temp_dir).Append(kTestAttachmentName)};
|
2020-06-24 09:03:47 +02:00
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
crashpad::CrashpadClient client;
|
2019-05-01 22:19:21 -07:00
|
|
|
if (!InstallHandler(&client,
|
|
|
|
options.start_handler_at_crash,
|
|
|
|
handler_path,
|
2020-06-24 09:03:47 +02:00
|
|
|
base::FilePath(temp_dir),
|
|
|
|
attachments)) {
|
2018-02-22 13:29:05 -08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2022-01-20 08:57:13 -08:00
|
|
|
if (options.set_first_chance_handler) {
|
|
|
|
client.SetFirstChanceExceptionHandler(HandleCrashSuccessfully);
|
|
|
|
}
|
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
if (options.set_last_chance_handler) {
|
|
|
|
client.SetLastChanceExceptionHandler(HandleCrashSuccessfullyAfterReporting);
|
|
|
|
}
|
|
|
|
|
2022-01-19 15:00:24 -05:00
|
|
|
#if BUILDFLAG(IS_ANDROID)
|
2019-03-29 15:22:11 -07:00
|
|
|
if (android_set_abort_message) {
|
|
|
|
android_set_abort_message(kTestAbortMessage);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
if (options.crash_non_main_thread) {
|
|
|
|
CrashThread thread(options, &client);
|
|
|
|
thread.Start();
|
|
|
|
thread.Join();
|
|
|
|
} else {
|
|
|
|
DoCrash(options, &client);
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
class StartHandlerForSelfInChildTest : public MultiprocessExec {
|
2018-02-22 13:29:05 -08:00
|
|
|
public:
|
2019-05-01 22:19:21 -07:00
|
|
|
StartHandlerForSelfInChildTest(const StartHandlerForSelfTestOptions& options)
|
|
|
|
: MultiprocessExec(), options_(options) {
|
|
|
|
SetChildTestMainFunction("StartHandlerForSelfTestChild");
|
2022-01-20 08:57:13 -08:00
|
|
|
if (!options.set_first_chance_handler) {
|
|
|
|
switch (options.crash_type) {
|
|
|
|
case CrashType::kSimulated:
|
|
|
|
// kTerminationNormal, EXIT_SUCCESS
|
|
|
|
break;
|
|
|
|
case CrashType::kBuiltinTrap:
|
|
|
|
SetExpectedChildTerminationBuiltinTrap();
|
|
|
|
break;
|
|
|
|
case CrashType::kInfiniteRecursion:
|
|
|
|
SetExpectedChildTermination(TerminationReason::kTerminationSignal,
|
|
|
|
SIGSEGV);
|
|
|
|
break;
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
case CrashType::kSegvWithTagBits:
|
|
|
|
SetExpectedChildTermination(TerminationReason::kTerminationSignal,
|
|
|
|
SIGSEGV);
|
2023-08-31 17:27:07 +00:00
|
|
|
break;
|
|
|
|
case CrashType::kFakeSegv:
|
|
|
|
if (!options.set_last_chance_handler) {
|
|
|
|
SetExpectedChildTermination(TerminationReason::kTerminationSignal,
|
|
|
|
SIGSEGV);
|
|
|
|
} else {
|
|
|
|
SetExpectedChildTermination(TerminationReason::kTerminationNormal,
|
|
|
|
EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
break;
|
2022-01-20 08:57:13 -08:00
|
|
|
}
|
2019-05-01 22:19:21 -07:00
|
|
|
}
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
StartHandlerForSelfInChildTest(const StartHandlerForSelfInChildTest&) =
|
|
|
|
delete;
|
|
|
|
StartHandlerForSelfInChildTest& operator=(
|
|
|
|
const StartHandlerForSelfInChildTest&) = delete;
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
private:
|
|
|
|
void MultiprocessParent() override {
|
|
|
|
ScopedTempDir temp_dir;
|
|
|
|
VMSize temp_dir_length = temp_dir.path().value().size();
|
|
|
|
ASSERT_TRUE(LoggingWriteFile(
|
|
|
|
WritePipeHandle(), &temp_dir_length, sizeof(temp_dir_length)));
|
|
|
|
ASSERT_TRUE(LoggingWriteFile(
|
|
|
|
WritePipeHandle(), temp_dir.path().value().data(), temp_dir_length));
|
2019-05-01 22:19:21 -07:00
|
|
|
ASSERT_TRUE(
|
|
|
|
LoggingWriteFile(WritePipeHandle(), &options_, sizeof(options_)));
|
2018-02-22 13:29:05 -08:00
|
|
|
|
2020-07-16 11:30:21 -07:00
|
|
|
FileWriter writer;
|
|
|
|
base::FilePath test_attachment_path =
|
|
|
|
temp_dir.path().Append(kTestAttachmentName);
|
|
|
|
bool is_created = writer.Open(test_attachment_path,
|
|
|
|
FileWriteMode::kCreateOrFail,
|
|
|
|
FilePermissions::kOwnerOnly);
|
|
|
|
ASSERT_TRUE(is_created);
|
|
|
|
writer.Write(kTestAttachmentContent, sizeof(kTestAttachmentContent));
|
|
|
|
writer.Close();
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
if (options_.client_uses_signals && !options_.set_first_chance_handler &&
|
2023-08-31 17:27:07 +00:00
|
|
|
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)) {
|
2020-07-15 11:26:08 -07:00
|
|
|
// Wait for child's client signal handler.
|
|
|
|
char c;
|
|
|
|
EXPECT_TRUE(LoggingReadFileExactly(ReadPipeHandle(), &c, sizeof(c)));
|
|
|
|
}
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
// Wait for child to finish.
|
|
|
|
CheckedReadFileAtEOF(ReadPipeHandle());
|
|
|
|
|
|
|
|
auto database = CrashReportDatabase::Initialize(temp_dir.path());
|
|
|
|
ASSERT_TRUE(database);
|
|
|
|
|
|
|
|
std::vector<CrashReportDatabase::Report> reports;
|
2018-05-10 17:15:59 -07:00
|
|
|
ASSERT_EQ(database->GetCompletedReports(&reports),
|
|
|
|
CrashReportDatabase::kNoError);
|
|
|
|
EXPECT_EQ(reports.size(), 0u);
|
|
|
|
|
|
|
|
reports.clear();
|
2018-02-22 13:29:05 -08:00
|
|
|
ASSERT_EQ(database->GetPendingReports(&reports),
|
|
|
|
CrashReportDatabase::kNoError);
|
2019-05-01 22:19:21 -07:00
|
|
|
|
2022-01-20 08:57:13 -08:00
|
|
|
bool report_expected = !options_.set_first_chance_handler ||
|
|
|
|
options_.crash_type == CrashType::kSimulated;
|
|
|
|
ASSERT_EQ(reports.size(), report_expected ? 1u : 0u);
|
|
|
|
|
|
|
|
if (!report_expected) {
|
2019-05-01 22:19:21 -07:00
|
|
|
return;
|
|
|
|
}
|
2018-02-22 13:29:05 -08:00
|
|
|
|
2018-05-10 17:15:59 -07:00
|
|
|
std::unique_ptr<const CrashReportDatabase::UploadReport> report;
|
|
|
|
ASSERT_EQ(database->GetReportForUploading(reports[0].uuid, &report),
|
2018-02-22 13:29:05 -08:00
|
|
|
CrashReportDatabase::kNoError);
|
2021-12-13 13:48:45 -08:00
|
|
|
ValidateDump(options_, report.get());
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
StartHandlerForSelfTestOptions options_;
|
2018-02-22 13:29:05 -08:00
|
|
|
};
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
TEST_P(StartHandlerForSelfTest, StartHandlerInChild) {
|
2020-10-12 12:41:16 -07:00
|
|
|
#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
|
|
|
|
defined(UNDEFINED_SANITIZER)
|
2020-07-20 13:29:44 -07:00
|
|
|
if (Options().crash_type == CrashType::kInfiniteRecursion) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
#endif // defined(ADDRESS_SANITIZER)
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
|
2023-08-31 17:27:07 +00:00
|
|
|
// kFakeSegv does raise(SIGSEGV) to simulate a MTE error which is a SEGSEGV
|
|
|
|
// that doesn't get reraised automatically, but this causes the child process
|
|
|
|
// to flakily terminate normally on some bots (e.g. android-nougat-x86-rel)
|
|
|
|
// for some reason so this is skipped.
|
|
|
|
if (!Options().set_last_chance_handler &&
|
|
|
|
Options().crash_type == CrashType::kFakeSegv) {
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
if (Options().crash_type == CrashType::kSegvWithTagBits) {
|
|
|
|
#if !defined(ARCH_CPU_ARM64)
|
|
|
|
GTEST_SKIP() << "Testing for tag bits only exists on aarch64.";
|
2022-11-16 00:07:44 +00:00
|
|
|
#else
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
struct utsname uname_info;
|
|
|
|
ASSERT_EQ(uname(&uname_info), 0);
|
|
|
|
ASSERT_NE(uname_info.release, nullptr);
|
|
|
|
|
|
|
|
char* release = uname_info.release;
|
|
|
|
unsigned major = strtoul(release, &release, 10);
|
|
|
|
ASSERT_EQ(*release++, '.');
|
|
|
|
unsigned minor = strtoul(release, nullptr, 10);
|
|
|
|
|
|
|
|
if (major < 5 || (major == 5 && minor < 11)) {
|
|
|
|
GTEST_SKIP() << "Linux kernel v" << uname_info.release
|
|
|
|
<< " does not support SA_EXPOSE_TAGBITS";
|
|
|
|
}
|
2022-11-16 00:07:44 +00:00
|
|
|
#endif // !defined(ARCH_CPU_ARM64)
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
}
|
|
|
|
|
2019-05-01 22:19:21 -07:00
|
|
|
StartHandlerForSelfInChildTest test(Options());
|
2018-02-22 13:29:05 -08:00
|
|
|
test.Run();
|
|
|
|
}
|
|
|
|
|
2020-07-15 11:26:08 -07:00
|
|
|
INSTANTIATE_TEST_SUITE_P(
|
|
|
|
StartHandlerForSelfTestSuite,
|
|
|
|
StartHandlerForSelfTest,
|
|
|
|
testing::Combine(testing::Bool(),
|
|
|
|
testing::Bool(),
|
|
|
|
testing::Bool(),
|
|
|
|
testing::Bool(),
|
2021-12-13 13:48:45 -08:00
|
|
|
testing::Bool(),
|
2023-08-31 17:27:07 +00:00
|
|
|
testing::Bool(),
|
2020-07-15 11:26:08 -07:00
|
|
|
testing::Values(CrashType::kSimulated,
|
|
|
|
CrashType::kBuiltinTrap,
|
Add SA_EXPOSE_TAGBITS to crashpad's signal handler.
SA_EXPOSE_TAGBITS is a Linux >= 5.11 feature that allows si_addr to
contain the upper tag bits. This is a feature that allows signal
handlers to see the full upper address bits on aarch64, which consist of
TBI and MTE nibbles. For MTE, preserving these bits is of significant
importance, as it allows for precise use-after-free and buffer-overflow
diagnosis that's impossible without seeing these bits in the fault
address.
We unconditionally enable this feature on all kernels, as it's ignored
when unsupported (even on older kernels).
Tested on:
1. Linux x86 host, which is a no-op.
2. Android device with Linux 4.14, which is a no-op.
3. Android device with Linux 5.15, which passes. For posterity, my
config was:
| $ gn args out_arm64
| target_os = "android"
| android_ndk_root = "~/Android.sdk/ndk/21.4.7075529"
| android_api_level = 26
| target_cpu = "arm64"
| # NDK builds push libc++_shared.so, which is not present on newer Android
| # versions, so I hacked the runner to push the file. Maybe this should be
| # upstreamed at some point as well.
| $ git diff
| diff --git a/build/run_tests.py b/build/run_tests.py
| index 8ad19e34..64269c90 100755
| --- a/build/run_tests.py
| +++ b/build/run_tests.py
| @@ -273,7 +273,8 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| _adb_shell(adb_mkdir_command)
|
| # Push the test binary and any other build output to the device.
| - local_test_build_artifacts = []
| + local_test_build_artifacts = [
| + '~/Android.sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so']
| for artifact in test_build_artifacts:
| local_test_build_artifacts.append(os.path.join(
| binary_dir, artifact))
| @@ -294,6 +295,7 @@ def _RunOnAndroidTarget(binary_dir, test, android_device, extra_command_line):
| # The list of TERM values comes from Google Test’s
| # googletest/src/gtest.cc testing::internal::ShouldUseColor().
| env = {'CRASHPAD_TEST_DATA_ROOT': device_temp_dir}
| + env = {'LD_LIBRARY_PATH': device_out_dir}
| gtest_color = os.environ.get('GTEST_COLOR')
| if gtest_color in ('auto', None):
| if (sys.stdout.isatty() and
| $ ninja -C out_arm64 && python build/run_tests.py out_arm64/ \
| --gtest_filter=*StartHandlerForSelfTestSuite*
Change-Id: I293b36fcd08ffaca593dae8042299a39756defa0
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4024204
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Mitch Phillips <mitchp@google.com>
2022-11-14 15:25:09 -08:00
|
|
|
CrashType::kInfiniteRecursion,
|
2023-08-31 17:27:07 +00:00
|
|
|
CrashType::kSegvWithTagBits,
|
|
|
|
CrashType::kFakeSegv)));
|
2019-05-01 22:19:21 -07:00
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
// Test state for starting the handler for another process.
|
|
|
|
class StartHandlerForClientTest {
|
|
|
|
public:
|
|
|
|
StartHandlerForClientTest() = default;
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
StartHandlerForClientTest(const StartHandlerForClientTest&) = delete;
|
|
|
|
StartHandlerForClientTest& operator=(const StartHandlerForClientTest&) =
|
|
|
|
delete;
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
~StartHandlerForClientTest() = default;
|
|
|
|
|
2018-06-12 08:30:36 -07:00
|
|
|
bool Initialize(bool sanitize) {
|
|
|
|
sanitize_ = sanitize;
|
2019-05-02 13:55:08 -07:00
|
|
|
return UnixCredentialSocket::CreateCredentialSocketpair(&client_sock_,
|
|
|
|
&server_sock_);
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StartHandlerOnDemand() {
|
|
|
|
char c;
|
|
|
|
if (!LoggingReadFileExactly(server_sock_.get(), &c, sizeof(c))) {
|
|
|
|
ADD_FAILURE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::FilePath handler_path = TestPaths::Executable().DirName().Append(
|
|
|
|
FILE_PATH_LITERAL("crashpad_handler"));
|
|
|
|
|
|
|
|
CrashpadClient client;
|
|
|
|
if (!client.StartHandlerForClient(handler_path,
|
|
|
|
temp_dir_.path(),
|
|
|
|
base::FilePath(),
|
|
|
|
"",
|
|
|
|
std::map<std::string, std::string>(),
|
|
|
|
std::vector<std::string>(),
|
|
|
|
server_sock_.get())) {
|
|
|
|
ADD_FAILURE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExpectReport() {
|
|
|
|
auto database =
|
|
|
|
CrashReportDatabase::InitializeWithoutCreating(temp_dir_.path());
|
|
|
|
ASSERT_TRUE(database);
|
|
|
|
|
|
|
|
std::vector<CrashReportDatabase::Report> reports;
|
2018-06-12 08:30:36 -07:00
|
|
|
ASSERT_EQ(database->GetCompletedReports(&reports),
|
2018-02-22 13:29:05 -08:00
|
|
|
CrashReportDatabase::kNoError);
|
2018-06-12 08:30:36 -07:00
|
|
|
EXPECT_EQ(reports.size(), 0u);
|
2018-02-22 13:29:05 -08:00
|
|
|
|
2018-04-12 19:37:06 -07:00
|
|
|
reports.clear();
|
2018-06-12 08:30:36 -07:00
|
|
|
ASSERT_EQ(database->GetPendingReports(&reports),
|
2018-02-22 13:29:05 -08:00
|
|
|
CrashReportDatabase::kNoError);
|
2018-06-12 08:30:36 -07:00
|
|
|
if (sanitize_) {
|
|
|
|
EXPECT_EQ(reports.size(), 0u);
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(reports.size(), 1u);
|
|
|
|
}
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InstallHandler() {
|
|
|
|
auto signal_handler = SandboxedHandler::Get();
|
2018-06-12 08:30:36 -07:00
|
|
|
return signal_handler->Initialize(client_sock_.get(), sanitize_);
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// A signal handler that defers handler process startup to another, presumably
|
|
|
|
// more privileged, process.
|
|
|
|
class SandboxedHandler {
|
|
|
|
public:
|
2021-09-20 12:55:12 -07:00
|
|
|
SandboxedHandler(const SandboxedHandler&) = delete;
|
|
|
|
SandboxedHandler& operator=(const SandboxedHandler&) = delete;
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
static SandboxedHandler* Get() {
|
|
|
|
static SandboxedHandler* instance = new SandboxedHandler();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2018-06-12 08:30:36 -07:00
|
|
|
bool Initialize(FileHandle client_sock, bool sanitize) {
|
2018-02-22 13:29:05 -08:00
|
|
|
client_sock_ = client_sock;
|
2018-06-12 08:30:36 -07:00
|
|
|
sanitize_ = sanitize;
|
2018-02-22 13:29:05 -08:00
|
|
|
return Signals::InstallCrashHandlers(HandleCrash, 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SandboxedHandler() = default;
|
|
|
|
~SandboxedHandler() = delete;
|
|
|
|
|
|
|
|
static void HandleCrash(int signo, siginfo_t* siginfo, void* context) {
|
|
|
|
auto state = Get();
|
|
|
|
|
2019-06-28 15:20:01 -07:00
|
|
|
char c = 0;
|
2018-02-22 13:29:05 -08:00
|
|
|
CHECK(LoggingWriteFile(state->client_sock_, &c, sizeof(c)));
|
|
|
|
|
|
|
|
ExceptionInformation exception_information;
|
|
|
|
exception_information.siginfo_address =
|
|
|
|
FromPointerCast<decltype(exception_information.siginfo_address)>(
|
|
|
|
siginfo);
|
|
|
|
exception_information.context_address =
|
|
|
|
FromPointerCast<decltype(exception_information.context_address)>(
|
|
|
|
context);
|
|
|
|
exception_information.thread_id = syscall(SYS_gettid);
|
|
|
|
|
2019-04-23 09:59:29 -07:00
|
|
|
ExceptionHandlerProtocol::ClientInformation info;
|
2018-02-22 13:29:05 -08:00
|
|
|
info.exception_information_address =
|
|
|
|
FromPointerCast<decltype(info.exception_information_address)>(
|
|
|
|
&exception_information);
|
|
|
|
|
2018-06-12 08:30:36 -07:00
|
|
|
SanitizationInformation sanitization_info = {};
|
|
|
|
if (state->sanitize_) {
|
|
|
|
info.sanitization_information_address =
|
|
|
|
FromPointerCast<VMAddress>(&sanitization_info);
|
|
|
|
// Target a non-module address to prevent a crash dump.
|
|
|
|
sanitization_info.target_module_address =
|
|
|
|
FromPointerCast<VMAddress>(&sanitization_info);
|
|
|
|
}
|
|
|
|
|
2019-04-29 14:28:53 -07:00
|
|
|
ExceptionHandlerClient handler_client(state->client_sock_, false);
|
2018-02-22 13:29:05 -08:00
|
|
|
CHECK_EQ(handler_client.RequestCrashDump(info), 0);
|
|
|
|
|
|
|
|
Signals::RestoreHandlerAndReraiseSignalOnReturn(siginfo, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileHandle client_sock_;
|
2018-06-12 08:30:36 -07:00
|
|
|
bool sanitize_;
|
2018-02-22 13:29:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
ScopedTempDir temp_dir_;
|
|
|
|
ScopedFileHandle client_sock_;
|
|
|
|
ScopedFileHandle server_sock_;
|
2018-06-12 08:30:36 -07:00
|
|
|
bool sanitize_;
|
2018-02-22 13:29:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Tests starting the handler for a child process.
|
|
|
|
class StartHandlerForChildTest : public Multiprocess {
|
|
|
|
public:
|
|
|
|
StartHandlerForChildTest() = default;
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
StartHandlerForChildTest(const StartHandlerForChildTest&) = delete;
|
|
|
|
StartHandlerForChildTest& operator=(const StartHandlerForChildTest&) = delete;
|
|
|
|
|
2018-02-22 13:29:05 -08:00
|
|
|
~StartHandlerForChildTest() = default;
|
|
|
|
|
2018-06-12 08:30:36 -07:00
|
|
|
bool Initialize(bool sanitize) {
|
2018-02-22 13:29:05 -08:00
|
|
|
SetExpectedChildTerminationBuiltinTrap();
|
2018-06-12 08:30:36 -07:00
|
|
|
return test_state_.Initialize(sanitize);
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void MultiprocessParent() {
|
|
|
|
ASSERT_TRUE(test_state_.StartHandlerOnDemand());
|
|
|
|
|
|
|
|
// Wait for chlid to finish.
|
|
|
|
CheckedReadFileAtEOF(ReadPipeHandle());
|
|
|
|
|
|
|
|
test_state_.ExpectReport();
|
|
|
|
}
|
|
|
|
|
2024-08-14 13:09:43 +10:00
|
|
|
[[noreturn]] void MultiprocessChild() {
|
2018-02-22 13:29:05 -08:00
|
|
|
CHECK(test_state_.InstallHandler());
|
|
|
|
|
|
|
|
__builtin_trap();
|
|
|
|
|
2024-08-14 13:09:43 +10:00
|
|
|
NOTREACHED();
|
2018-02-22 13:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
StartHandlerForClientTest test_state_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(CrashpadClient, StartHandlerForChild) {
|
|
|
|
StartHandlerForChildTest test;
|
2018-06-12 08:30:36 -07:00
|
|
|
ASSERT_TRUE(test.Initialize(/* sanitize= */ false));
|
|
|
|
test.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(CrashpadClient, SanitizedChild) {
|
|
|
|
StartHandlerForChildTest test;
|
|
|
|
ASSERT_TRUE(test.Initialize(/* sanitize= */ true));
|
2018-02-22 13:29:05 -08:00
|
|
|
test.Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|