Bug 751585: Don't enforce ASLR for binary components on XP, because system DLLs don't have ASLR and trigger false positives. r=bsmedberg,ehsan a=lsblakk
authorKyle Huey <khuey@kylehuey.com>
Tue, 08 May 2012 11:06:09 -0700
changeset 92179 aa323b98df3682a29f32d3dfb5896bd94d86ae20
parent 92178 73f16a3b7c84a93e68dc043a352a6e0d7e4620a8
child 92180 f40f8e40bae81e5b0af7c0ca05d020e8e025f6c3
child 92182 435a483ffd84dfaa67f62e92dcec65d3cd83a7cb
child 92184 303d987789c5cd1b1a0504657b33b3aa3bc1ac01
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, ehsan, lsblakk
bugs751585
milestone13.0
Bug 751585: Don't enforce ASLR for binary components on XP, because system DLLs don't have ASLR and trigger false positives. r=bsmedberg,ehsan a=lsblakk
toolkit/xre/nsWindowsDllBlocklist.cpp
xpcom/tests/unit/test_comp_no_aslr.js
xpcom/tests/unit/xpcshell.ini
--- a/toolkit/xre/nsWindowsDllBlocklist.cpp
+++ b/toolkit/xre/nsWindowsDllBlocklist.cpp
@@ -185,16 +185,28 @@ struct RVAMap {
   operator const T*() const { return mMappedView; }
   const T* operator->() const { return mMappedView; }
 private:
   const T* mMappedView;
   void* mRealView;
 };
 
 bool
+IsVistaOrLater()
+{
+  OSVERSIONINFO info;
+
+  ZeroMemory(&info, sizeof(OSVERSIONINFO));
+  info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+  GetVersionEx(&info);
+
+  return info.dwMajorVersion >= 6;
+}
+
+bool
 CheckASLR(const wchar_t* path)
 {
   bool retval = false;
 
   HANDLE file = ::CreateFileW(path, GENERIC_READ, FILE_SHARE_READ,
                               NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
                               NULL);
   if (file != INVALID_HANDLE_VALUE) {
@@ -447,17 +459,17 @@ continue_loading:
     // Check to ensure that the DLL has ASLR.
     full_fname = getFullPath(filePath, fname);
     if (!full_fname) {
       // uh, we couldn't find the DLL at all, so...
       printf_stderr("LdrLoadDll: Blocking load of '%s' (SearchPathW didn't find it?)\n", dllName);
       return STATUS_DLL_NOT_FOUND;
     }
 
-    if (!CheckASLR(full_fname)) {
+    if (IsVistaOrLater() && !CheckASLR(full_fname)) {
       printf_stderr("LdrLoadDll: Blocking load of '%s'.  XPCOM components must support ASLR.\n", dllName);
       return STATUS_DLL_NOT_FOUND;
     }
   }
 
   return stub_LdrLoadDll(filePath, flags, moduleFileName, handle);
 }
 
--- a/xpcom/tests/unit/test_comp_no_aslr.js
+++ b/xpcom/tests/unit/test_comp_no_aslr.js
@@ -1,10 +1,18 @@
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function run_test() {
   let manifest = do_get_file('testcompnoaslr.manifest');
   Components.manager.autoRegister(manifest);
-  do_check_false("{335fb596-e52d-418f-b01c-1bf16ce5e7e4}" in Components.classesByID);
+  var sysInfo = Cc["@mozilla.org/system-info;1"].
+                getService(Ci.nsIPropertyBag2);
+  var ver = parseFloat(sysInfo.getProperty("version"));
+  if (ver < 6.0) {
+    // This is disabled on pre-Vista OSs.
+    do_check_true("{335fb596-e52d-418f-b01c-1bf16ce5e7e4}" in Components.classesByID);
+  } else {
+    do_check_false("{335fb596-e52d-418f-b01c-1bf16ce5e7e4}" in Components.classesByID);
+  }
 }
--- a/xpcom/tests/unit/xpcshell.ini
+++ b/xpcom/tests/unit/xpcshell.ini
@@ -39,9 +39,9 @@ skip-if = os == "win" # See bug: 676412
 [test_symlinks.js]
 # Bug 676998: test fails consistently on Android
 fail-if = os == "android"
 [test_systemInfo.js]
 # Bug 676998: test fails consistently on Android
 fail-if = os == "android"
 [test_versioncomparator.js]
 [test_comp_no_aslr.js]
-fail-if = os != "win"
+skip-if = os != "win"