Bug 1322554: don't block threads based on MEM_IMAGE; safer exiting thread; don't block null threadproc to allow crashfirefox.exe; r=dmajor draft
authorCarl Corcoran <carlco@gmail.com>
Wed, 29 Mar 2017 12:35:10 +0200
changeset 552978 656d0a38542331404a859b8a868a2b3279810986
parent 552977 8dc24c4d384cca89cd24acb0dcc7841b2d403a90
child 621968 5f5552b2bd0c27a9640f5e9a230f441a44904a01
push id51530
push userbmo:ccorcoran@mozilla.com
push dateWed, 29 Mar 2017 10:46:27 +0000
reviewersdmajor
bugs1322554
milestone55.0a1
Bug 1322554: don't block threads based on MEM_IMAGE; safer exiting thread; don't block null threadproc to allow crashfirefox.exe; r=dmajor MozReview-Commit-ID: IrcdhIMk1CC
mozglue/build/WindowsDllBlocklist.cpp
--- a/mozglue/build/WindowsDllBlocklist.cpp
+++ b/mozglue/build/WindowsDllBlocklist.cpp
@@ -701,35 +701,46 @@ continue_loading:
 #ifdef DEBUG_very_verbose
   printf_stderr("LdrLoadDll: continuing load... ('%S')\n", moduleFileName->Buffer);
 #endif
 
   return stub_LdrLoadDll(filePath, flags, moduleFileName, handle);
 }
 
 static bool
-ShouldBlockThread(void* aStartAddress, void* aThreadParam)
+ShouldBlockThread(void* aStartAddress)
 {
+  // allows crashfirefox.exe to continue to work. also if your threadproc is null, this crash is intentional.
+  if(aStartAddress == 0)
+    return false;
+
   bool shouldBlock = false;
   MEMORY_BASIC_INFORMATION startAddressInfo;
   if (VirtualQuery(aStartAddress, &startAddressInfo, sizeof(startAddressInfo))) {
     shouldBlock |= startAddressInfo.State != MEM_COMMIT;
     shouldBlock |= startAddressInfo.Protect != PAGE_EXECUTE_READ;
-    shouldBlock |= !(startAddressInfo.Type & MEM_IMAGE);
+    //shouldBlock |= !(startAddressInfo.Type & MEM_IMAGE); in the future we may want to be stricter by adding this check. for now playing it safe.
   }
 
   return shouldBlock;
 }
 
+// allows blocked threads to still run normally through BaseThreadInitThunk, in case there's any magic there that we shouldn't skip.
+DWORD WINAPI
+NopThreadProc(void* aThreadParam)
+{
+  return 0;
+}
+
 static MOZ_NORETURN void __fastcall
 patched_BaseThreadInitThunk(BOOL aIsInitialThread, void* aStartAddress,
                             void* aThreadParam)
 {
-  if (ShouldBlockThread(aStartAddress, aThreadParam)) {
-    ExitThread(1);
+  if (ShouldBlockThread(aStartAddress)) {
+    aStartAddress = NopThreadProc;
   }
 
   stub_BaseThreadInitThunk(aIsInitialThread, aStartAddress, aThreadParam);
 }
 
 WindowsDllInterceptor NtDllIntercept;
 WindowsDllInterceptor Kernel32DllIntercept;