diff options
author | Hans Wennborg <hans@hanshq.net> | 2019-08-26 12:15:54 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2019-08-26 12:15:54 +0000 |
commit | 82783a7657f958d35c5dfc150ddf2cffaf097c66 (patch) | |
tree | df643676b0b1ba7bb02ee84c1ca76a991d096fae | |
parent | 612450792b64df6ad80dc81297f99bb7088d6d05 (diff) | |
download | compiler-rt-82783a7657f958d35c5dfc150ddf2cffaf097c66.tar.gz |
Merge r369708 - [Sanitizer] checks ASLR on FreeBSD
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_90@369897 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/asan/asan_rtl.cc | 2 | ||||
-rw-r--r-- | lib/msan/msan.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux.cc | 29 |
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc index db8dcd068..c502965c1 100644 --- a/lib/asan/asan_rtl.cc +++ b/lib/asan/asan_rtl.cc @@ -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/lib/msan/msan.cc b/lib/msan/msan.cc index c62e5cd4c..d83e441e6 100644 --- a/lib/msan/msan.cc +++ b/lib/msan/msan.cc @@ -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/lib/sanitizer_common/sanitizer_linux.cc b/lib/sanitizer_common/sanitizer_linux.cc index 455fd4c86..73960fee5 100644 --- a/lib/sanitizer_common/sanitizer_linux.cc +++ b/lib/sanitizer_common/sanitizer_linux.cc @@ -2011,6 +2011,35 @@ 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 |