2016-10-17 23:28:00 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "crasher"
|
|
|
|
|
2014-04-23 23:57:32 +02:00
|
|
|
#include <assert.h>
|
2016-12-15 02:33:46 +01:00
|
|
|
#include <dirent.h>
|
2014-04-23 23:57:32 +02:00
|
|
|
#include <errno.h>
|
2023-08-09 01:00:30 +02:00
|
|
|
#include <error.h>
|
2016-10-08 01:42:05 +02:00
|
|
|
#include <fcntl.h>
|
2014-04-23 23:57:32 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-07-07 21:33:50 +02:00
|
|
|
#include <sys/mman.h>
|
2017-02-09 21:37:39 +01:00
|
|
|
#include <sys/prctl.h>
|
2014-04-23 23:57:32 +02:00
|
|
|
#include <unistd.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2023-08-09 01:00:30 +02:00
|
|
|
#include <android-base/file.h>
|
|
|
|
#include <android-base/strings.h>
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
// We test both kinds of logging.
|
|
|
|
#include <android-base/logging.h>
|
2017-01-13 00:44:06 +01:00
|
|
|
#include <log/log.h>
|
2014-04-30 18:24:08 +02:00
|
|
|
|
2017-03-03 04:01:20 +01:00
|
|
|
#include "seccomp_policy.h"
|
|
|
|
|
2016-06-16 02:29:00 +02:00
|
|
|
#if defined(STATIC_CRASHER)
|
2016-10-19 03:17:52 +02:00
|
|
|
#include "debuggerd/handler.h"
|
2016-06-16 02:29:00 +02:00
|
|
|
#endif
|
|
|
|
|
2022-04-13 23:55:36 +02:00
|
|
|
extern "C" void android_set_abort_message(const char* msg);
|
|
|
|
|
2017-02-02 01:59:15 +01:00
|
|
|
#if defined(__arm__)
|
|
|
|
// See https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt for details.
|
|
|
|
#define __kuser_helper_version (*(int32_t*) 0xffff0ffc)
|
|
|
|
typedef void * (__kuser_get_tls_t)(void);
|
|
|
|
#define __kuser_get_tls (*(__kuser_get_tls_t*) 0xffff0fe0)
|
|
|
|
typedef int (__kuser_cmpxchg_t)(int oldval, int newval, volatile int *ptr);
|
|
|
|
#define __kuser_cmpxchg (*(__kuser_cmpxchg_t*) 0xffff0fc0)
|
|
|
|
typedef void (__kuser_dmb_t)(void);
|
|
|
|
#define __kuser_dmb (*(__kuser_dmb_t*) 0xffff0fa0)
|
|
|
|
typedef int (__kuser_cmpxchg64_t)(const int64_t*, const int64_t*, volatile int64_t*);
|
|
|
|
#define __kuser_cmpxchg64 (*(__kuser_cmpxchg64_t*) 0xffff0f60)
|
|
|
|
#endif
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
#define noinline __attribute__((__noinline__))
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
// Avoid name mangling so that stacks are more readable.
|
|
|
|
extern "C" {
|
2013-04-24 02:14:56 +02:00
|
|
|
|
2023-08-09 01:00:30 +02:00
|
|
|
void crash1();
|
|
|
|
void crash_no_stack();
|
|
|
|
void crash_bti();
|
|
|
|
void crash_pac();
|
2016-05-10 22:29:58 +02:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
int do_action(const char* arg);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void maybe_abort() {
|
2014-04-23 23:57:32 +02:00
|
|
|
if (time(0) != 42) {
|
2013-06-12 23:04:34 +02:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
char* smash_stack_dummy_buf;
|
|
|
|
noinline void smash_stack_dummy_function(volatile int* plen) {
|
2014-12-12 02:46:33 +01:00
|
|
|
smash_stack_dummy_buf[*plen] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This must be marked with "__attribute__ ((noinline))", to ensure the
|
|
|
|
// compiler generates the proper stack guards around this function.
|
|
|
|
// Assign local array address to global variable to force stack guards.
|
|
|
|
// Use another noinline function to corrupt the stack.
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int smash_stack(volatile int* plen) {
|
|
|
|
printf("%s: deliberately corrupting stack...\n", getprogname());
|
2014-12-12 02:46:33 +01:00
|
|
|
|
|
|
|
char buf[128];
|
|
|
|
smash_stack_dummy_buf = buf;
|
|
|
|
// This should corrupt stack guards and make process abort.
|
|
|
|
smash_stack_dummy_function(plen);
|
|
|
|
return 0;
|
2013-02-14 23:41:57 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:55:14 +02:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Winfinite-recursion"
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
void* global = 0; // So GCC doesn't optimize the tail recursion out of overflow_stack.
|
2013-07-16 02:19:02 +02:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void overflow_stack(void* p) {
|
2013-04-24 02:14:56 +02:00
|
|
|
void* buf[1];
|
|
|
|
buf[0] = p;
|
2013-07-16 02:19:02 +02:00
|
|
|
global = buf;
|
2013-04-24 02:14:56 +02:00
|
|
|
overflow_stack(&buf);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-30 08:55:14 +02:00
|
|
|
#pragma clang diagnostic pop
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void* thread_callback(void* raw_arg) {
|
|
|
|
const char* arg = reinterpret_cast<const char*>(raw_arg);
|
|
|
|
return reinterpret_cast<void*>(static_cast<uintptr_t>(do_action(arg)));
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int do_action_on_thread(const char* arg) {
|
2012-12-10 23:15:42 +01:00
|
|
|
pthread_t t;
|
2016-12-15 02:33:46 +01:00
|
|
|
pthread_create(&t, nullptr, thread_callback, const_cast<char*>(arg));
|
|
|
|
void* result = nullptr;
|
2012-12-10 23:15:42 +01:00
|
|
|
pthread_join(t, &result);
|
2016-12-15 02:33:46 +01:00
|
|
|
return reinterpret_cast<uintptr_t>(result);
|
2012-12-10 23:15:42 +01:00
|
|
|
}
|
|
|
|
|
2017-09-20 22:37:24 +02:00
|
|
|
noinline int crash_null() {
|
|
|
|
int (*null_func)() = nullptr;
|
|
|
|
return null_func();
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int crash3(int a) {
|
|
|
|
*reinterpret_cast<int*>(0xdead) = a;
|
2013-06-12 23:04:34 +02:00
|
|
|
return a*4;
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int crash2(int a) {
|
2013-06-12 23:04:34 +02:00
|
|
|
a = crash3(a) + 2;
|
|
|
|
return a*3;
|
2013-03-08 10:17:35 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int crash(int a) {
|
2013-06-12 23:04:34 +02:00
|
|
|
a = crash2(a) + 1;
|
|
|
|
return a*2;
|
2013-03-08 10:17:35 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 00:22:52 +01:00
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wfree-nonheap-object"
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void abuse_heap() {
|
2013-06-12 23:04:34 +02:00
|
|
|
char buf[16];
|
2016-12-15 02:33:46 +01:00
|
|
|
free(buf); // GCC is smart enough to warn about this, but we're doing it deliberately.
|
2013-03-08 10:17:35 +01:00
|
|
|
}
|
2021-03-17 00:22:52 +01:00
|
|
|
#pragma clang diagnostic pop
|
2013-03-08 10:17:35 +01:00
|
|
|
|
2017-06-30 21:46:31 +02:00
|
|
|
noinline void leak() {
|
|
|
|
while (true) {
|
|
|
|
void* mapping =
|
2023-06-16 01:23:56 +02:00
|
|
|
mmap(nullptr, getpagesize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
2017-06-30 21:46:31 +02:00
|
|
|
static_cast<volatile char*>(mapping)[0] = 'a';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void sigsegv_non_null() {
|
2014-06-17 23:55:47 +02:00
|
|
|
int* a = (int *)(&do_action);
|
|
|
|
*a = 42;
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline void fprintf_null() {
|
2023-03-03 02:33:28 +01:00
|
|
|
FILE* sneaky_null = nullptr;
|
|
|
|
fprintf(sneaky_null, "oops");
|
2016-12-15 02:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
noinline void readdir_null() {
|
2023-04-01 01:50:37 +02:00
|
|
|
DIR* sneaky_null = nullptr;
|
|
|
|
readdir(sneaky_null);
|
2016-12-15 02:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
noinline int strlen_null() {
|
|
|
|
char* sneaky_null = nullptr;
|
|
|
|
return strlen(sneaky_null);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usage() {
|
|
|
|
fprintf(stderr, "usage: %s KIND\n", getprogname());
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fprintf(stderr, "where KIND is:\n");
|
|
|
|
fprintf(stderr, " smash-stack overwrite a -fstack-protector guard\n");
|
|
|
|
fprintf(stderr, " stack-overflow recurse until the stack overflows\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, " nostack crash with a NULL stack pointer\n");
|
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " heap-usage cause a libc abort by abusing a heap function\n");
|
2017-09-20 22:37:24 +02:00
|
|
|
fprintf(stderr, " call-null cause a crash by calling through a nullptr\n");
|
2017-06-30 21:46:31 +02:00
|
|
|
fprintf(stderr, " leak leak memory until we get OOM-killed\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " abort call abort()\n");
|
2022-04-13 23:55:36 +02:00
|
|
|
fprintf(stderr, " abort_with_msg call abort() setting an abort message\n");
|
|
|
|
fprintf(stderr, " abort_with_null_msg call abort() setting a null abort message\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " assert call assert() without a function\n");
|
|
|
|
fprintf(stderr, " assert2 call assert() with a function\n");
|
|
|
|
fprintf(stderr, " exit call exit(1)\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " fortify fail a _FORTIFY_SOURCE check\n");
|
2018-06-02 01:35:47 +02:00
|
|
|
fprintf(stderr, " fdsan_file close a file descriptor that's owned by a FILE*\n");
|
|
|
|
fprintf(stderr, " fdsan_dir close a file descriptor that's owned by a DIR*\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, " seccomp fail a seccomp check\n");
|
2019-04-15 22:03:48 +02:00
|
|
|
fprintf(stderr, " xom read execute-only memory\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " LOG_ALWAYS_FATAL call liblog LOG_ALWAYS_FATAL\n");
|
|
|
|
fprintf(stderr, " LOG_ALWAYS_FATAL_IF call liblog LOG_ALWAYS_FATAL_IF\n");
|
|
|
|
fprintf(stderr, " LOG-FATAL call libbase LOG(FATAL)\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " SIGFPE cause a SIGFPE\n");
|
2018-05-30 21:55:04 +02:00
|
|
|
fprintf(stderr, " SIGILL cause a SIGILL\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " SIGSEGV cause a SIGSEGV at address 0x0 (synonym: crash)\n");
|
|
|
|
fprintf(stderr, " SIGSEGV-non-null cause a SIGSEGV at a non-zero address\n");
|
|
|
|
fprintf(stderr, " SIGSEGV-unmapped mmap/munmap a region of memory and then attempt to access it\n");
|
|
|
|
fprintf(stderr, " SIGTRAP cause a SIGTRAP\n");
|
2017-02-02 01:59:15 +01:00
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, " fprintf-NULL pass a null pointer to fprintf\n");
|
|
|
|
fprintf(stderr, " readdir-NULL pass a null pointer to readdir\n");
|
|
|
|
fprintf(stderr, " strlen-NULL pass a null pointer to strlen\n");
|
2017-02-17 19:26:48 +01:00
|
|
|
fprintf(stderr, " pthread_join-NULL pass a null pointer to pthread_join\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, "\n");
|
2017-02-09 21:37:39 +01:00
|
|
|
fprintf(stderr, " no_new_privs set PR_SET_NO_NEW_PRIVS and then abort\n");
|
|
|
|
fprintf(stderr, "\n");
|
2023-08-09 01:00:30 +02:00
|
|
|
#if defined(__arm__)
|
|
|
|
fprintf(stderr, "Also, since this is an arm32 binary:\n");
|
|
|
|
fprintf(stderr, " kuser_helper_version call kuser_helper_version\n");
|
|
|
|
fprintf(stderr, " kuser_get_tls call kuser_get_tls\n");
|
|
|
|
fprintf(stderr, " kuser_cmpxchg call kuser_cmpxchg\n");
|
|
|
|
fprintf(stderr, " kuser_memory_barrier call kuser_memory_barrier\n");
|
|
|
|
fprintf(stderr, " kuser_cmpxchg64 call kuser_cmpxchg64\n");
|
|
|
|
#endif
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
fprintf(stderr, "Also, since this is an arm64 binary:\n");
|
|
|
|
fprintf(stderr, " bti fail a branch target identification (BTI) check\n");
|
|
|
|
fprintf(stderr, " pac fail a pointer authentication (PAC) check\n");
|
|
|
|
#endif
|
|
|
|
fprintf(stderr, "\n");
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, "prefix any of the above with 'thread-' to run on a new thread\n");
|
|
|
|
fprintf(stderr, "prefix any of the above with 'exhaustfd-' to exhaust\n");
|
|
|
|
fprintf(stderr, "all available file descriptors before crashing.\n");
|
|
|
|
fprintf(stderr, "prefix any of the above with 'wait-' to wait until input is received on stdin\n");
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2013-04-24 02:14:56 +02:00
|
|
|
|
2023-08-09 01:00:30 +02:00
|
|
|
[[maybe_unused]] static void CheckCpuFeature(const std::string& name) {
|
|
|
|
std::string cpuinfo;
|
|
|
|
if (!android::base::ReadFileToString("/proc/cpuinfo", &cpuinfo)) {
|
|
|
|
error(1, errno, "couldn't read /proc/cpuinfo");
|
|
|
|
}
|
|
|
|
std::vector<std::string> lines = android::base::Split(cpuinfo, "\n");
|
|
|
|
for (std::string_view line : lines) {
|
|
|
|
if (!android::base::ConsumePrefix(&line, "Features\t:")) continue;
|
|
|
|
std::vector<std::string> features = android::base::Split(std::string(line), " ");
|
|
|
|
if (std::find(features.begin(), features.end(), name) == features.end()) {
|
|
|
|
error(1, 0, "/proc/cpuinfo does not report feature '%s'", name.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
noinline int do_action(const char* arg) {
|
|
|
|
// Prefixes.
|
2016-11-01 01:37:37 +01:00
|
|
|
if (!strncmp(arg, "wait-", strlen("wait-"))) {
|
|
|
|
char buf[1];
|
2018-09-24 22:03:25 +02:00
|
|
|
UNUSED(TEMP_FAILURE_RETRY(read(STDIN_FILENO, buf, sizeof(buf))));
|
2016-11-01 01:37:37 +01:00
|
|
|
return do_action(arg + strlen("wait-"));
|
|
|
|
} else if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) {
|
2016-10-08 01:42:05 +02:00
|
|
|
errno = 0;
|
|
|
|
while (errno != EMFILE) {
|
|
|
|
open("/dev/null", O_RDONLY);
|
|
|
|
}
|
|
|
|
return do_action(arg + strlen("exhaustfd-"));
|
|
|
|
} else if (!strncmp(arg, "thread-", strlen("thread-"))) {
|
2012-12-10 23:15:42 +01:00
|
|
|
return do_action_on_thread(arg + strlen("thread-"));
|
2016-12-15 02:33:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actions.
|
|
|
|
if (!strcasecmp(arg, "SIGSEGV-non-null")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
sigsegv_non_null();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "smash-stack")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
volatile int len = 128;
|
|
|
|
return smash_stack(&len);
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "stack-overflow")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
overflow_stack(nullptr);
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "nostack")) {
|
2023-08-09 01:00:30 +02:00
|
|
|
crash_no_stack();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "exit")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
exit(1);
|
2017-09-20 22:37:24 +02:00
|
|
|
} else if (!strcasecmp(arg, "call-null")) {
|
|
|
|
return crash_null();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
return crash(42);
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "abort")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
maybe_abort();
|
2022-04-13 23:55:36 +02:00
|
|
|
} else if (!strcasecmp(arg, "abort_with_msg")) {
|
|
|
|
android_set_abort_message("Aborting due to crasher");
|
|
|
|
maybe_abort();
|
|
|
|
} else if (!strcasecmp(arg, "abort_with_null")) {
|
|
|
|
android_set_abort_message(nullptr);
|
|
|
|
maybe_abort();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "assert")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
__assert("some_file.c", 123, "false");
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "assert2")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
__assert2("some_file.c", 123, "some_function", "false");
|
2018-09-24 22:03:25 +02:00
|
|
|
#if !defined(__clang_analyzer__)
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "fortify")) {
|
2018-09-24 22:03:25 +02:00
|
|
|
// FORTIFY is disabled when running clang-tidy and other tools, so this
|
|
|
|
// shouldn't depend on internal implementation details of it.
|
2018-06-02 01:35:47 +02:00
|
|
|
char buf[10];
|
|
|
|
__read_chk(-1, buf, 32, 10);
|
|
|
|
while (true) pause();
|
2018-09-24 22:03:25 +02:00
|
|
|
#endif
|
2018-06-02 01:35:47 +02:00
|
|
|
} else if (!strcasecmp(arg, "fdsan_file")) {
|
|
|
|
FILE* f = fopen("/dev/null", "r");
|
|
|
|
close(fileno(f));
|
|
|
|
} else if (!strcasecmp(arg, "fdsan_dir")) {
|
|
|
|
DIR* d = opendir("/dev/");
|
|
|
|
close(dirfd(d));
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "LOG(FATAL)")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
LOG(FATAL) << "hello " << 123;
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
LOG_ALWAYS_FATAL("hello %s", "world");
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
LOG_ALWAYS_FATAL_IF(true, "hello %s", "world");
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "SIGFPE")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
raise(SIGFPE);
|
|
|
|
return EXIT_SUCCESS;
|
2018-05-30 21:55:04 +02:00
|
|
|
} else if (!strcasecmp(arg, "SIGILL")) {
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
__asm__ volatile(".word 0\n");
|
|
|
|
#elif defined(__arm__)
|
|
|
|
__asm__ volatile(".word 0xe7f0def0\n");
|
|
|
|
#elif defined(__i386__) || defined(__x86_64__)
|
|
|
|
__asm__ volatile("ud2\n");
|
2022-10-12 16:27:54 +02:00
|
|
|
#elif defined(__riscv)
|
|
|
|
__asm__ volatile("unimp\n");
|
2018-05-30 21:55:04 +02:00
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "SIGTRAP")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
raise(SIGTRAP);
|
|
|
|
return EXIT_SUCCESS;
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "fprintf-NULL")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
fprintf_null();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "readdir-NULL")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
readdir_null();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "strlen-NULL")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
return strlen_null();
|
2017-02-17 19:26:48 +01:00
|
|
|
} else if (!strcasecmp(arg, "pthread_join-NULL")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
return pthread_join(0, nullptr);
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "heap-usage")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
abuse_heap();
|
2017-06-30 21:46:31 +02:00
|
|
|
} else if (!strcasecmp(arg, "leak")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
leak();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else if (!strcasecmp(arg, "SIGSEGV-unmapped")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
char* map = reinterpret_cast<char*>(
|
|
|
|
mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
|
|
|
|
munmap(map, sizeof(int));
|
|
|
|
map[0] = '8';
|
2017-02-02 01:59:15 +01:00
|
|
|
} else if (!strcasecmp(arg, "seccomp")) {
|
2018-06-02 01:35:47 +02:00
|
|
|
set_system_seccomp_filter();
|
|
|
|
syscall(99999);
|
2019-04-15 22:03:48 +02:00
|
|
|
#if defined(__LP64__)
|
|
|
|
} else if (!strcasecmp(arg, "xom")) {
|
|
|
|
// Try to read part of our code, which will fail if XOM is active.
|
|
|
|
printf("*%lx = %lx\n", reinterpret_cast<long>(usage), *reinterpret_cast<long*>(usage));
|
|
|
|
#endif
|
2017-02-02 01:59:15 +01:00
|
|
|
#if defined(__arm__)
|
|
|
|
} else if (!strcasecmp(arg, "kuser_helper_version")) {
|
|
|
|
return __kuser_helper_version;
|
|
|
|
} else if (!strcasecmp(arg, "kuser_get_tls")) {
|
|
|
|
return !__kuser_get_tls();
|
|
|
|
} else if (!strcasecmp(arg, "kuser_cmpxchg")) {
|
|
|
|
return __kuser_cmpxchg(0, 0, 0);
|
|
|
|
} else if (!strcasecmp(arg, "kuser_memory_barrier")) {
|
|
|
|
__kuser_dmb();
|
|
|
|
} else if (!strcasecmp(arg, "kuser_cmpxchg64")) {
|
|
|
|
return __kuser_cmpxchg64(0, 0, 0);
|
2023-08-09 01:00:30 +02:00
|
|
|
#endif
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
} else if (!strcasecmp(arg, "bti")) {
|
|
|
|
CheckCpuFeature("bti");
|
|
|
|
crash_bti();
|
|
|
|
} else if (!strcasecmp(arg, "pac")) {
|
|
|
|
CheckCpuFeature("paca");
|
|
|
|
crash_pac();
|
2017-02-02 01:59:15 +01:00
|
|
|
#endif
|
2017-02-09 21:37:39 +01:00
|
|
|
} else if (!strcasecmp(arg, "no_new_privs")) {
|
|
|
|
if (prctl(PR_SET_NO_NEW_PRIVS, 1) != 0) {
|
|
|
|
fprintf(stderr, "prctl(PR_SET_NO_NEW_PRIVS, 1) failed: %s\n", strerror(errno));
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
abort();
|
2016-12-15 02:33:46 +01:00
|
|
|
} else {
|
|
|
|
return usage();
|
2012-12-10 23:15:42 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
fprintf(stderr, "%s: exiting normally!\n", getprogname());
|
2013-04-24 02:14:56 +02:00
|
|
|
return EXIT_SUCCESS;
|
2012-12-10 23:15:42 +01:00
|
|
|
}
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
int main(int argc, char** argv) {
|
2016-06-16 02:29:00 +02:00
|
|
|
#if defined(STATIC_CRASHER)
|
|
|
|
debuggerd_callbacks_t callbacks = {
|
2020-03-06 01:46:15 +01:00
|
|
|
.get_process_info = []() {
|
2016-06-16 02:29:00 +02:00
|
|
|
static struct {
|
|
|
|
size_t size;
|
|
|
|
char msg[32];
|
|
|
|
} msg;
|
|
|
|
|
|
|
|
msg.size = strlen("dummy abort message");
|
|
|
|
memcpy(msg.msg, "dummy abort message", strlen("dummy abort message"));
|
2020-03-06 01:46:15 +01:00
|
|
|
return debugger_process_info{
|
|
|
|
.abort_msg = reinterpret_cast<void*>(&msg),
|
|
|
|
};
|
2016-06-16 02:29:00 +02:00
|
|
|
},
|
|
|
|
.post_dump = nullptr
|
|
|
|
};
|
|
|
|
debuggerd_init(&callbacks);
|
|
|
|
#endif
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
if (argc == 1) crash1();
|
|
|
|
else if (argc == 2) return do_action(argv[1]);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2016-12-15 02:33:46 +01:00
|
|
|
return usage();
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2016-12-15 02:33:46 +01:00
|
|
|
|
|
|
|
};
|