linux: override exception thread ID

When a crash dump request is received over a socket, the message
includes a stack address of the thread requesting the dump. This can
be used to override the ExceptionInfo's thread ID which may be
incorrect in the handler's PID namespace.

Bug: crashpad:286
Change-Id: I053cf709c5eeefb73b31328f16a806510e1bd35d
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1759280
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Joshua Peraza 2019-08-16 17:09:58 -07:00 committed by Commit Bot
parent ec56fc6a38
commit 3a6c6012ba
3 changed files with 21 additions and 6 deletions

View File

@ -95,13 +95,18 @@ bool CrashReportExceptionHandler::HandleExceptionWithConnection(
return false;
}
if (requesting_thread_id && requesting_thread_stack_address) {
*requesting_thread_id = process_snapshot.FindThreadWithStackAddress(
pid_t local_requesting_thread_id = -1;
if (requesting_thread_stack_address) {
local_requesting_thread_id = process_snapshot.FindThreadWithStackAddress(
requesting_thread_stack_address);
}
if (!process_snapshot.InitializeException(
info.exception_information_address)) {
if (requesting_thread_id) {
*requesting_thread_id = local_requesting_thread_id;
}
if (!process_snapshot.InitializeException(info.exception_information_address,
local_requesting_thread_id)) {
Metrics::ExceptionCaptureResult(
Metrics::CaptureResult::kExceptionInitializationFailed);
return false;

View File

@ -64,7 +64,8 @@ pid_t ProcessSnapshotLinux::FindThreadWithStackAddress(
}
bool ProcessSnapshotLinux::InitializeException(
LinuxVMAddress exception_info_address) {
LinuxVMAddress exception_info_address,
pid_t exception_thread_id) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
DCHECK(!exception_);
@ -75,6 +76,10 @@ bool ProcessSnapshotLinux::InitializeException(
return false;
}
if (exception_thread_id >= 0) {
info.thread_id = exception_thread_id;
}
exception_.reset(new internal::ExceptionSnapshotLinux());
if (!exception_->Initialize(&process_reader_,
info.siginfo_address,

View File

@ -70,7 +70,12 @@ class ProcessSnapshotLinux final : public ProcessSnapshot {
//!
//! \param[in] exception_info The address of an ExceptionInformation in the
//! target process' address space.
bool InitializeException(LinuxVMAddress exception_info);
//! \param[in] exception_thread_id The thread ID to assocaite the thread with.
//! Optional. If -1, the exception thread will be identified by the
//! ExceptionInformation struct which contains the thread ID in the target
//! process' namespace.
bool InitializeException(LinuxVMAddress exception_info,
pid_t exception_thread_id = -1);
//! \brief Sets the value to be returned by ReportID().
//!