From dc25251af9e38a417f85fd6bc5a5d985a25dd207 Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Thu, 31 Aug 2023 04:05:12 -0700 Subject: [PATCH] Enable sandboxed stack traces for coverage PiperOrigin-RevId: 561611676 Change-Id: I852eec8fc3728da1ae0b4bca8ccc9a628b8b5adc --- sandboxed_api/sandbox2/BUILD.bazel | 1 + sandboxed_api/sandbox2/CMakeLists.txt | 1 + sandboxed_api/sandbox2/stack_trace.cc | 22 +++++++++------------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/sandboxed_api/sandbox2/BUILD.bazel b/sandboxed_api/sandbox2/BUILD.bazel index 453e8e8..70532cc 100644 --- a/sandboxed_api/sandbox2/BUILD.bazel +++ b/sandboxed_api/sandbox2/BUILD.bazel @@ -416,6 +416,7 @@ cc_library( ":comms", ":executor", ":limits", + ":mounts", ":namespace", ":policy", ":policybuilder", diff --git a/sandboxed_api/sandbox2/CMakeLists.txt b/sandboxed_api/sandbox2/CMakeLists.txt index d5db33c..feed59e 100644 --- a/sandboxed_api/sandbox2/CMakeLists.txt +++ b/sandboxed_api/sandbox2/CMakeLists.txt @@ -374,6 +374,7 @@ target_link_libraries(sandbox2_stack_trace absl::time sandbox2::client sandbox2::limits + sandbox2::mounts sandbox2::policybuilder sandbox2::util sandbox2::unwind diff --git a/sandboxed_api/sandbox2/stack_trace.cc b/sandboxed_api/sandbox2/stack_trace.cc index 3062854..ec41539 100644 --- a/sandboxed_api/sandbox2/stack_trace.cc +++ b/sandboxed_api/sandbox2/stack_trace.cc @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -42,6 +41,8 @@ #include "sandboxed_api/sandbox2/comms.h" #include "sandboxed_api/sandbox2/executor.h" #include "sandboxed_api/sandbox2/limits.h" +#include "sandboxed_api/sandbox2/mounts.h" +#include "sandboxed_api/sandbox2/namespace.h" #include "sandboxed_api/sandbox2/policy.h" #include "sandboxed_api/sandbox2/policybuilder.h" #include "sandboxed_api/sandbox2/regs.h" @@ -173,7 +174,8 @@ absl::StatusOr> StackTracePeer::GetPolicy( absl::StrCat(target_pid), "maps")) // Add the binary itself. - .AddFileAt(exe_path, app_path); + .AddFileAt(exe_path, app_path) + .AllowLlvmCoverage(); return builder.TryBuild(); } @@ -320,20 +322,14 @@ absl::StatusOr> GetStackTrace( "Could not obtain stacktrace, regs == nullptr"); } - // Show a warning if sandboxed libunwind is requested but we're running in - // an ASAN/coverage build (= we can't use sandboxed libunwind). - if (const bool coverage_enabled = - getenv("COVERAGE") != nullptr; - absl::GetFlag(FLAGS_sandbox_libunwind_crash_handler) && - (sapi::sanitizers::IsAny() || coverage_enabled)) { - LOG_IF(WARNING, sapi::sanitizers::IsAny()) - << "Sanitizer build, using non-sandboxed libunwind"; - LOG_IF(WARNING, coverage_enabled) - << "Coverage build, using non-sandboxed libunwind"; + if (!absl::GetFlag(FLAGS_sandbox_libunwind_crash_handler)) { return UnsafeGetStackTrace(regs->pid()); } - if (!absl::GetFlag(FLAGS_sandbox_libunwind_crash_handler)) { + // Show a warning if sandboxed libunwind is requested but we're running in + // a sanitizer build (= we can't use sandboxed libunwind). + if (sapi::sanitizers::IsAny()) { + LOG(WARNING) << "Sanitizer build, using non-sandboxed libunwind"; return UnsafeGetStackTrace(regs->pid()); }