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

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 04:56:50 PDT 2019


devnexen created this revision.
devnexen added reviewers: vitalybuka, emaste, dim.
Herald added subscribers: llvm-commits, Sanitizers, krytarowski.
Herald added projects: LLVM, Sanitizers.

- Especially MemorySanitizer fails if those sysctl configs are enabled.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D66582

Files:
  compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp


Index: compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ compiler-rt/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\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\n");
+    Die();
+  }
 #else
   // Do nothing
 #endif


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


More information about the llvm-commits mailing list