diff options
author | Josh Gao <jmgao@google.com> | 2018-09-12 13:55:47 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2018-09-12 18:12:13 -0700 |
commit | 6f9eeecd2b7d0e194bd710a8bdc0222ebe35d28d (patch) | |
tree | 3a8fcf55fb0726bbb311aaf00ab3068518df86cc /debuggerd/debuggerd_test.cpp | |
parent | d812d0dada5ef908419a5633a640420d0a1b1955 (diff) |
Fix multithreaded backtraces for seccomp processes.
Add threads to the existing seccomp backtrace test to prevent
regressing this.
Bug: http://b/114139908
Bug: http://b/115349586
Test: debuggerd_test32
Test: debuggerd_test64
Change-Id: I07fbe1619b60f0008deb045a249f9045404478c2
Diffstat (limited to 'debuggerd/debuggerd_test.cpp')
-rw-r--r-- | debuggerd/debuggerd_test.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index e2ea480e5..388facb45 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -587,9 +587,28 @@ static const char* const kDebuggerdSeccompPolicy = "/system/etc/seccomp_policy/crash_dump." ABI_STRING ".policy"; static pid_t seccomp_fork_impl(void (*prejail)()) { - unique_fd policy_fd(open(kDebuggerdSeccompPolicy, O_RDONLY | O_CLOEXEC)); - if (policy_fd == -1) { - LOG(FATAL) << "failed to open policy " << kDebuggerdSeccompPolicy; + std::string policy; + if (!android::base::ReadFileToString(kDebuggerdSeccompPolicy, &policy)) { + PLOG(FATAL) << "failed to read policy file"; + } + + // Allow a bunch of syscalls used by the tests. + policy += "\nclone: 1"; + policy += "\nsigaltstack: 1"; + policy += "\nnanosleep: 1"; + + FILE* tmp_file = tmpfile(); + if (!tmp_file) { + PLOG(FATAL) << "tmpfile failed"; + } + + unique_fd tmp_fd(dup(fileno(tmp_file))); + if (!android::base::WriteStringToFd(policy, tmp_fd.get())) { + PLOG(FATAL) << "failed to write policy to tmpfile"; + } + + if (lseek(tmp_fd.get(), 0, SEEK_SET) != 0) { + PLOG(FATAL) << "failed to seek tmp_fd"; } ScopedMinijail jail{minijail_new()}; @@ -600,7 +619,7 @@ static pid_t seccomp_fork_impl(void (*prejail)()) { minijail_no_new_privs(jail.get()); minijail_log_seccomp_filter_failures(jail.get()); minijail_use_seccomp_filter(jail.get()); - minijail_parse_seccomp_filters_from_fd(jail.get(), policy_fd.release()); + minijail_parse_seccomp_filters_from_fd(jail.get(), tmp_fd.release()); pid_t result = fork(); if (result == -1) { @@ -735,6 +754,16 @@ TEST_F(CrasherTest, seccomp_tombstone) { ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal"); } +extern "C" void foo() { + LOG(INFO) << "foo"; + std::this_thread::sleep_for(1s); +} + +extern "C" void bar() { + LOG(INFO) << "bar"; + std::this_thread::sleep_for(1s); +} + TEST_F(CrasherTest, seccomp_backtrace) { int intercept_result; unique_fd output_fd; @@ -742,6 +771,11 @@ TEST_F(CrasherTest, seccomp_backtrace) { static const auto dump_type = kDebuggerdNativeBacktrace; StartProcess( []() { + std::thread a(foo); + std::thread b(bar); + + std::this_thread::sleep_for(100ms); + raise_debugger_signal(dump_type); _exit(0); }, @@ -756,6 +790,8 @@ TEST_F(CrasherTest, seccomp_backtrace) { std::string result; ConsumeFd(std::move(output_fd), &result); ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal"); + ASSERT_BACKTRACE_FRAME(result, "foo"); + ASSERT_BACKTRACE_FRAME(result, "bar"); } TEST_F(CrasherTest, seccomp_crash_logcat) { |