From 3a6c6012ba2b9ed662872ccaf7d276d56240943b Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Fri, 16 Aug 2019 17:09:58 -0700 Subject: [PATCH] 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 Commit-Queue: Joshua Peraza --- handler/linux/crash_report_exception_handler.cc | 13 +++++++++---- snapshot/linux/process_snapshot_linux.cc | 7 ++++++- snapshot/linux/process_snapshot_linux.h | 7 ++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/handler/linux/crash_report_exception_handler.cc b/handler/linux/crash_report_exception_handler.cc index 1688df79..875afec3 100644 --- a/handler/linux/crash_report_exception_handler.cc +++ b/handler/linux/crash_report_exception_handler.cc @@ -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; diff --git a/snapshot/linux/process_snapshot_linux.cc b/snapshot/linux/process_snapshot_linux.cc index bada3a95..35f870ec 100644 --- a/snapshot/linux/process_snapshot_linux.cc +++ b/snapshot/linux/process_snapshot_linux.cc @@ -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, diff --git a/snapshot/linux/process_snapshot_linux.h b/snapshot/linux/process_snapshot_linux.h index 705cb5f9..06b72aff 100644 --- a/snapshot/linux/process_snapshot_linux.h +++ b/snapshot/linux/process_snapshot_linux.h @@ -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(). //!