This revision was automatically updated to reflect the committed changes.
Closed by commit rL350030: [xray] Detect MPROTECT and error out when it's 
enabled (on NetBSD) (authored by mgorny, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D56049?vs=179419&id=179444#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56049/new/

https://reviews.llvm.org/D56049

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
  compiler-rt/trunk/lib/xray/xray_init.cc

Index: compiler-rt/trunk/lib/xray/xray_init.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_init.cc
+++ compiler-rt/trunk/lib/xray/xray_init.cc
@@ -67,6 +67,9 @@
   if (atomic_load(&XRayInitialized, memory_order_acquire))
     return;
 
+  // XRAY is not compatible with PaX MPROTECT
+  CheckMPROTECT();
+
   if (!atomic_load(&XRayFlagsInitialized, memory_order_acquire)) {
     initializeFlags();
     atomic_store(&XRayFlagsInitialized, true, memory_order_release);
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -89,6 +89,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void PlatformPrepareForSandboxing(__sanitizer_sandbox_arguments *args) {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
@@ -377,6 +377,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 uptr GetPageSize() {
   return sysconf(_SC_PAGESIZE);
 }
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
@@ -1016,6 +1016,10 @@
   // Do nothing
 }
 
+void CheckMPROTECT() {
+  // Do nothing
+}
+
 char **GetArgv() {
   // FIXME: Actually implement this function.
   return 0;
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cc
@@ -2023,6 +2023,30 @@
 #endif
 }
 
+void CheckMPROTECT() {
+#if SANITIZER_NETBSD
+  int mib[3];
+  int paxflags;
+  uptr len = sizeof(paxflags);
+
+  mib[0] = CTL_PROC;
+  mib[1] = internal_getpid();
+  mib[2] = PROC_PID_PAXFLAGS;
+
+  if (UNLIKELY(internal_sysctl(mib, 3, &paxflags, &len, NULL, 0) == -1)) {
+    Printf("sysctl failed\n");
+    Die();
+  }
+
+  if (UNLIKELY(paxflags & CTL_PROC_PAXFLAGS_MPROTECT)) {
+    Printf("This sanitizer is not compatible with enabled MPROTECT\n");
+    Die();
+  }
+#else
+  // Do nothing
+#endif
+}
+
 void PrintModuleMap() { }
 
 void CheckNoDeepBind(const char *filename, int flag) {
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -223,6 +223,7 @@
 u32 GetUid();
 void ReExec();
 void CheckASLR();
+void CheckMPROTECT();
 char **GetArgv();
 char **GetEnviron();
 void PrintCmdline();
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_rtems.cc
@@ -98,6 +98,7 @@
 void InitializePlatformEarly() {}
 void MaybeReexec() {}
 void CheckASLR() {}
+void CheckMPROTECT() {}
 void DisableCoreDumperIfNecessary() {}
 void InstallDeadlySignalHandlers(SignalHandlerType handler) {}
 void SetAlternateSignalStack() {}
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to