From 0b62b4b5acbf8978619de9a473d719a102a37652 Mon Sep 17 00:00:00 2001 From: Aaron Klotz Date: Wed, 18 Dec 2019 15:23:02 +0000 Subject: [PATCH] Bug 1603714: Add temporary, Nightly-only crash annotations to UntrustedModulesData and dependencies to determine failure location; r=handyman Differential Revision: https://phabricator.services.mozilla.com/D57558 --HG-- extra : moz-landing-system : lando --- .../telemetry/other/CombinedStacks.h | 18 +++++++ .../telemetry/other/ProcessedStack.h | 19 +++++++ toolkit/crashreporter/CrashAnnotations.yaml | 15 ++++++ toolkit/xre/UntrustedModulesData.h | 50 +++++++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/toolkit/components/telemetry/other/CombinedStacks.h b/toolkit/components/telemetry/other/CombinedStacks.h index 97c67bdae256..c35fcc9908b3 100644 --- a/toolkit/components/telemetry/other/CombinedStacks.h +++ b/toolkit/components/telemetry/other/CombinedStacks.h @@ -67,6 +67,18 @@ JSObject* CreateJSStackObject(JSContext* cx, const CombinedStacks& stacks); namespace IPC { +#if defined(NIGHTLY_BUILD) +# define ANNOTATE_READ_FAILURE() \ + CrashReporter::AnnotateCrashReport( \ + CrashReporter::Annotation:: \ + UntrustedModulesDataCombinedStackReadFailure, \ + __LINE__) +#else +# define ANNOTATE_READ_FAILURE() \ + do { \ + } while (false) +#endif // defined(NIGHTLY_BUILD) + template <> struct ParamTraits { typedef mozilla::Telemetry::CombinedStacks paramType; @@ -81,18 +93,22 @@ struct ParamTraits { static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mModules)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mStacks)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mNextIndex)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mMaxStacksCount)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -100,6 +116,8 @@ struct ParamTraits { } }; +#undef ANNOTATE_READ_FAILURE + } // namespace IPC #endif // CombinedStacks_h__ diff --git a/toolkit/components/telemetry/other/ProcessedStack.h b/toolkit/components/telemetry/other/ProcessedStack.h index cb0cae64ca17..b4ed7135a95e 100644 --- a/toolkit/components/telemetry/other/ProcessedStack.h +++ b/toolkit/components/telemetry/other/ProcessedStack.h @@ -11,6 +11,7 @@ #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/Vector.h" +#include "nsExceptionHandler.h" #include "nsString.h" #if defined(MOZ_GECKO_PROFILER) # include "shared-libraries.h" @@ -87,6 +88,18 @@ class BatchProcessedStackGenerator { namespace IPC { +#if defined(NIGHTLY_BUILD) +# define ANNOTATE_READ_FAILURE() \ + CrashReporter::AnnotateCrashReport( \ + CrashReporter::Annotation:: \ + UntrustedModulesDataProcessedStackReadFailure, \ + __LINE__) +#else +# define ANNOTATE_READ_FAILURE() \ + do { \ + } while (false) +#endif // defined(NIGHTLY_BUILD) + template <> struct ParamTraits { typedef mozilla::Telemetry::ProcessedStack::Module paramType; @@ -99,10 +112,12 @@ struct ParamTraits { static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mName)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mBreakpadId)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -122,10 +137,12 @@ struct ParamTraits { static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mOffset)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mModIndex)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -133,6 +150,8 @@ struct ParamTraits { } }; +#undef ANNOTATE_READ_FAILURE + } // namespace IPC #endif // ProcessedStack_h__ diff --git a/toolkit/crashreporter/CrashAnnotations.yaml b/toolkit/crashreporter/CrashAnnotations.yaml index 4b0e227ff66d..80479a9a6167 100644 --- a/toolkit/crashreporter/CrashAnnotations.yaml +++ b/toolkit/crashreporter/CrashAnnotations.yaml @@ -883,6 +883,21 @@ UnmarshalActCtxManifestPath: Proxy stream unmarshalling current activation context manifest path. type: string +UntrustedModulesDataCombinedStackReadFailure: + description: > + Location of failure reading UntrustedModulesData combined stack info over IPC + type: integer + +UntrustedModulesDataProcessedStackReadFailure: + description: > + Location of failure reading UntrustedModulesData processed stack info over IPC + type: integer + +UntrustedModulesDataReadFailure: + description: > + Location of failure reading UntrustedModulesData over IPC + type: integer + UptimeTS: description: > Uptime in seconds. This annotation uses a string instead of an integer diff --git a/toolkit/xre/UntrustedModulesData.h b/toolkit/xre/UntrustedModulesData.h index ba48f7ed1a5c..58867db720c8 100644 --- a/toolkit/xre/UntrustedModulesData.h +++ b/toolkit/xre/UntrustedModulesData.h @@ -20,6 +20,7 @@ # include "mozilla/Vector.h" # include "mozilla/WinHeaderOnlyUtils.h" # include "nsCOMPtr.h" +# include "nsExceptionHandler.h" # include "nsHashKeys.h" # include "nsIFile.h" # include "nsISupportsImpl.h" @@ -218,6 +219,17 @@ class ModulesMapResult final { namespace IPC { +# if defined(NIGHTLY_BUILD) +# define ANNOTATE_READ_FAILURE() \ + CrashReporter::AnnotateCrashReport( \ + CrashReporter::Annotation::UntrustedModulesDataReadFailure, \ + __LINE__) +# else +# define ANNOTATE_READ_FAILURE() \ + do { \ + } while (false) +# endif // defined(NIGHTLY_BUILD) + template <> struct ParamTraits { typedef mozilla::ModuleVersion paramType; @@ -230,6 +242,7 @@ struct ParamTraits { paramType* aResult) { uint64_t ver; if (!aMsg->ReadUInt64(aIter, &ver)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -251,12 +264,14 @@ struct ParamTraits { paramType* aResult) { uint32_t source; if (!aMsg->ReadUInt32(aIter, &source)) { + ANNOTATE_READ_FAILURE(); return false; } aResult->mSource = static_cast(source); if (!ReadParam(aMsg, aIter, &aResult->mVendor)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -293,6 +308,7 @@ struct ParamTraits { nsAutoString resolvedDosName; if (!ReadParam(aMsg, aIter, &resolvedDosName)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -301,23 +317,28 @@ struct ParamTraits { } else if (NS_FAILED(NS_NewLocalFile( resolvedDosName, false, getter_AddRefs(aResult->mResolvedDosName)))) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mSanitizedDllName)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mVersion)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mVendorInfo)) { + ANNOTATE_READ_FAILURE(); return false; } uint32_t trustFlags; if (!aMsg->ReadUInt32(aIter, &trustFlags)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -344,17 +365,20 @@ struct ParamTraits { paramType* aResult) { uint32_t count; if (!ReadParam(aMsg, aIter, &count)) { + ANNOTATE_READ_FAILURE(); return false; } for (uint32_t current = 0; current < count; ++current) { nsAutoString key; if (!ReadParam(aMsg, aIter, &key) || key.IsEmpty()) { + ANNOTATE_READ_FAILURE(); return false; } RefPtr rec(new mozilla::ModuleRecord()); if (!ReadParam(aMsg, aIter, rec.get())) { + ANNOTATE_READ_FAILURE(); return false; } @@ -379,6 +403,7 @@ struct ParamTraits { paramType* aResult) { uint32_t len; if (!aMsg->ReadUInt32(aIter, &len)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -386,16 +411,19 @@ struct ParamTraits { // Vector representation. auto& vec = aResult->mModuleNtPaths.as(); if (!vec.reserve(len)) { + ANNOTATE_READ_FAILURE(); return false; } for (uint32_t idx = 0; idx < len; ++idx) { nsString str; if (!ReadParam(aMsg, aIter, &str)) { + ANNOTATE_READ_FAILURE(); return false; } if (!vec.emplaceBack(std::move(str))) { + ANNOTATE_READ_FAILURE(); return false; } } @@ -446,30 +474,36 @@ struct ParamTraits { paramType* aResult) { uint32_t processType; if (!aMsg->ReadUInt32(aIter, &processType)) { + ANNOTATE_READ_FAILURE(); return false; } aResult->mProcessType = static_cast(processType); if (!aMsg->ReadULong(aIter, &aResult->mPid)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mElapsed)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mModules)) { + ANNOTATE_READ_FAILURE(); return false; } // We read mEvents manually so that we can use ReadEvent defined below. uint32_t eventsLen; if (!ReadParam(aMsg, aIter, &eventsLen)) { + ANNOTATE_READ_FAILURE(); return false; } if (!aResult->mEvents.resize(eventsLen)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -481,18 +515,22 @@ struct ParamTraits { } if (!ReadParam(aMsg, aIter, &aResult->mStacks)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mXULLoadDurationMS)) { + ANNOTATE_READ_FAILURE(); return false; } if (!aMsg->ReadUInt32(aIter, &aResult->mSanitizationFailures)) { + ANNOTATE_READ_FAILURE(); return false; } if (!aMsg->ReadUInt32(aIter, &aResult->mTrustTestFailures)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -525,36 +563,44 @@ struct ParamTraits { mozilla::ProcessedModuleLoadEvent* aResult, const mozilla::ModulesMap& aModulesMap) { if (!aMsg->ReadUInt64(aIter, &aResult->mProcessUptimeMS)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mLoadDurationMS)) { + ANNOTATE_READ_FAILURE(); return false; } if (!aMsg->ReadULong(aIter, &aResult->mThreadId)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mThreadName)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mRequestedDllName)) { + ANNOTATE_READ_FAILURE(); return false; } if (!ReadParam(aMsg, aIter, &aResult->mBaseAddress)) { + ANNOTATE_READ_FAILURE(); return false; } nsAutoString resolvedNtName; if (!ReadParam(aMsg, aIter, &resolvedNtName)) { + ANNOTATE_READ_FAILURE(); return false; } aResult->mModule = aModulesMap.Get(resolvedNtName); if (!aResult->mModule) { + ANNOTATE_READ_FAILURE(); return false; } @@ -574,10 +620,12 @@ struct ParamTraits { static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { if (!ReadParam(aMsg, aIter, &aResult->mModules)) { + ANNOTATE_READ_FAILURE(); return false; } if (!aMsg->ReadUInt32(aIter, &aResult->mTrustTestFailures)) { + ANNOTATE_READ_FAILURE(); return false; } @@ -585,6 +633,8 @@ struct ParamTraits { } }; +# undef ANNOTATE_READ_FAILURE + } // namespace IPC #else // defined(XP_WIN)