[PATCH] D66582: [Sanitizer] checks ASLR on FreeBSD

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 14:35:31 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL369708: [Sanitizer] checks ASLR on FreeBSD (authored by devnexen, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D66582?vs=216586&id=216721#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66582

Files:
  compiler-rt/trunk/lib/asan/asan_rtl.cpp
  compiler-rt/trunk/lib/msan/msan.cpp
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2011,6 +2011,33 @@
     CHECK_NE(personality(old_personality | ADDR_NO_RANDOMIZE), -1);
     ReExec();
   }
+#elif SANITIZER_FREEBSD
+  int aslr_pie;
+  uptr len = sizeof(aslr_pie);
+#if SANITIZER_WORDSIZE == 64
+  if (UNLIKELY(internal_sysctlbyname("kern.elf64.aslr.pie_enable",
+      &aslr_pie, &len, NULL, 0) == -1)) {
+    // We're making things less 'dramatic' here since
+    // the OID is not necessarily guaranteed to be here
+    // just yet regarding FreeBSD release
+    return;
+  }
+
+  if (aslr_pie > 0) {
+    Printf("This sanitizer is not compatible with enabled ASLR and binaries compiled with PIE\n");
+    Die();
+  }
+#endif
+  // there might be 32 bits compat for 64 bits
+  if (UNLIKELY(internal_sysctlbyname("kern.elf32.aslr.pie_enable",
+      &aslr_pie, &len, NULL, 0) == -1)) {
+    return;
+  }
+
+  if (aslr_pie > 0) {
+    Printf("This sanitizer is not compatible with enabled ASLR and binaries compiled with PIE\n");
+    Die();
+  }
 #else
   // Do nothing
 #endif
Index: compiler-rt/trunk/lib/msan/msan.cpp
===================================================================
--- compiler-rt/trunk/lib/msan/msan.cpp
+++ compiler-rt/trunk/lib/msan/msan.cpp
@@ -403,7 +403,6 @@
   AvoidCVE_2016_2143();
 
   CacheBinaryName();
-  CheckASLR();
   InitializeFlags();
 
   // Install tool-specific callbacks in sanitizer_common.
@@ -412,6 +411,7 @@
   __sanitizer_set_report_path(common_flags()->log_path);
 
   InitializeInterceptors();
+  CheckASLR();
   InitTlsSize();
   InstallDeadlySignalHandlers(MsanOnDeadlySignal);
   InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
Index: compiler-rt/trunk/lib/asan/asan_rtl.cpp
===================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cpp
+++ compiler-rt/trunk/lib/asan/asan_rtl.cpp
@@ -402,7 +402,6 @@
   asan_init_is_running = true;
 
   CacheBinaryName();
-  CheckASLR();
 
   // Initialize flags. This must be done early, because most of the
   // initialization steps look at flags().
@@ -450,6 +449,7 @@
   SetLowLevelAllocateCallback(OnLowLevelAllocate);
 
   InitializeAsanInterceptors();
+  CheckASLR();
 
   // Enable system log ("adb logcat") on Android.
   // Doing this before interceptors are initialized crashes in:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66582.216721.patch
Type: text/x-patch
Size: 2528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190822/1db263e4/attachment.bin>


More information about the llvm-commits mailing list