Bug 1361410: Don't hook BaseThreadInitThunk when WRusr.dll is loaded, mitigating a crash; r?dmajor draft
authorCarl Corcoran <carlco@gmail.com>
Thu, 17 Aug 2017 15:05:17 +0200
changeset 649740 4f6e7d97a13da91b82a6e6984c058d7691f710ea
parent 648046 932388b8c22c9775264e543697ce918415db9e23
child 727171 f953ec52d710104031b145b2d4ad1cddf63a11a6
push id75131
push userbmo:ccorcoran@mozilla.com
push dateMon, 21 Aug 2017 07:46:21 +0000
reviewersdmajor
bugs1361410
milestone57.0a1
Bug 1361410: Don't hook BaseThreadInitThunk when WRusr.dll is loaded, mitigating a crash; r?dmajor MozReview-Commit-ID: KqWq2bHT0CE
mozglue/build/WindowsDllBlocklist.cpp
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -861,27 +861,30 @@ DllBlocklist_Initialize(uint32_t aInitFl
   if (!IsWin8OrLater()) {
     // The crash that this hook works around is only seen on Win7.
     Kernel32Intercept.AddHook("RtlInstallFunctionTableCallback",
                               reinterpret_cast<intptr_t>(patched_RtlInstallFunctionTableCallback),
                               (void**)&stub_RtlInstallFunctionTableCallback);
   }
 #endif
 
-#ifdef _M_IX86 // Minimize impact; crashes in BaseThreadInitThunk are vastly more frequent on x86
-  if(!Kernel32Intercept.AddDetour("BaseThreadInitThunk",
+#ifdef _M_IX86 // Minimize impact. Crashes in BaseThreadInitThunk are more frequent on x86
+
+  // Bug 1361410: WRusr.dll will overwrite our hook and cause a crash.
+  // Workaround: If we detect WRusr.dll, don't hook.
+  if (!GetModuleHandleW(L"WRusr.dll")) {
+    if(!Kernel32Intercept.AddDetour("BaseThreadInitThunk",
                                     reinterpret_cast<intptr_t>(patched_BaseThreadInitThunk),
                                     (void**) &stub_BaseThreadInitThunk)) {
 #ifdef DEBUG
-    printf_stderr("BaseThreadInitThunk hook failed\n");
+      printf_stderr("BaseThreadInitThunk hook failed\n");
 #endif
+    }
   }
 #endif // _M_IX86
-
-
 }
 
 MFBT_API void
 DllBlocklist_WriteNotes(HANDLE file)
 {
   DWORD nBytes;
 
   WriteFile(file, kBlockedDllsParameter, kBlockedDllsParameterLen, &nBytes, nullptr);