diff options
author | David Carlier <devnexen@gmail.com> | 2019-08-22 21:36:35 +0000 |
---|---|---|
committer | David Carlier <devnexen@gmail.com> | 2019-08-22 21:36:35 +0000 |
commit | e2ed800d622567b35968a27f8784705fb48190f5 (patch) | |
tree | 6eafd208cbd12a2399df0982e3052c0c3205a94c /compiler-rt/lib | |
parent | 64adf7b6aece24888864bb9227f77ee228d69197 (diff) | |
download | bcm5719-llvm-e2ed800d622567b35968a27f8784705fb48190f5.tar.gz bcm5719-llvm-e2ed800d622567b35968a27f8784705fb48190f5.zip |
[Sanitizer] checks ASLR on FreeBSD
- Especially MemorySanitizer fails if those sysctl configs are enabled.
Reviewers: vitalybuka, emaste, dim
Reviewed By: dim
Differential Revision: https://reviews.llvm.org/D66582
llvm-svn: 369708
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cpp | 2 | ||||
-rw-r--r-- | compiler-rt/lib/msan/msan.cpp | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 27 |
3 files changed, 29 insertions, 2 deletions
diff --git a/compiler-rt/lib/asan/asan_rtl.cpp b/compiler-rt/lib/asan/asan_rtl.cpp index b16ca950518..f720126098b 100644 --- a/compiler-rt/lib/asan/asan_rtl.cpp +++ b/compiler-rt/lib/asan/asan_rtl.cpp @@ -402,7 +402,6 @@ static void AsanInitInternal() { 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 @@ static void AsanInitInternal() { SetLowLevelAllocateCallback(OnLowLevelAllocate); InitializeAsanInterceptors(); + CheckASLR(); // Enable system log ("adb logcat") on Android. // Doing this before interceptors are initialized crashes in: diff --git a/compiler-rt/lib/msan/msan.cpp b/compiler-rt/lib/msan/msan.cpp index 1bc505e442c..f5b05c460d8 100644 --- a/compiler-rt/lib/msan/msan.cpp +++ b/compiler-rt/lib/msan/msan.cpp @@ -403,7 +403,6 @@ void __msan_init() { AvoidCVE_2016_2143(); CacheBinaryName(); - CheckASLR(); InitializeFlags(); // Install tool-specific callbacks in sanitizer_common. @@ -412,6 +411,7 @@ void __msan_init() { __sanitizer_set_report_path(common_flags()->log_path); InitializeInterceptors(); + CheckASLR(); InitTlsSize(); InstallDeadlySignalHandlers(MsanOnDeadlySignal); InstallAtExitHandler(); // Needs __cxa_atexit interceptor. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 1ed6af33fb8..01be223d3e0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2011,6 +2011,33 @@ void CheckASLR() { 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 |