|
80 | 80 |
|
81 | 81 | #if SANITIZER_FREEBSD
|
82 | 82 | #include <sys/exec.h>
|
| 83 | +#include <sys/procctl.h> |
83 | 84 | #include <sys/sysctl.h>
|
84 | 85 | #include <machine/atomic.h>
|
85 | 86 | extern "C" {
|
@@ -2187,30 +2188,14 @@ void CheckASLR() {
|
2187 | 2188 | ReExec();
|
2188 | 2189 | }
|
2189 | 2190 | #elif SANITIZER_FREEBSD
|
2190 |
| - int aslr_pie; |
2191 |
| - uptr len = sizeof(aslr_pie); |
2192 |
| -#if SANITIZER_WORDSIZE == 64 |
2193 |
| - if (UNLIKELY(internal_sysctlbyname("kern.elf64.aslr.pie_enable", |
2194 |
| - &aslr_pie, &len, NULL, 0) == -1)) { |
| 2191 | + int aslr_status; |
| 2192 | + if (UNLIKELY(procctl(P_PID, 0, PROC_ASLR_STATUS, &aslr_status) == -1)) { |
2195 | 2193 | // We're making things less 'dramatic' here since
|
2196 |
| - // the OID is not necessarily guaranteed to be here |
| 2194 | + // the cmd is not necessarily guaranteed to be here |
2197 | 2195 | // just yet regarding FreeBSD release
|
2198 | 2196 | return;
|
2199 | 2197 | }
|
2200 |
| - |
2201 |
| - if (aslr_pie > 0) { |
2202 |
| - Printf("This sanitizer is not compatible with enabled ASLR " |
2203 |
| - "and binaries compiled with PIE\n"); |
2204 |
| - Die(); |
2205 |
| - } |
2206 |
| -#endif |
2207 |
| - // there might be 32 bits compat for 64 bits |
2208 |
| - if (UNLIKELY(internal_sysctlbyname("kern.elf32.aslr.pie_enable", |
2209 |
| - &aslr_pie, &len, NULL, 0) == -1)) { |
2210 |
| - return; |
2211 |
| - } |
2212 |
| - |
2213 |
| - if (aslr_pie > 0) { |
| 2198 | + if ((aslr_status & PROC_ASLR_ACTIVE) != 0) { |
2214 | 2199 | Printf("This sanitizer is not compatible with enabled ASLR "
|
2215 | 2200 | "and binaries compiled with PIE\n");
|
2216 | 2201 | Die();
|
|
0 commit comments