Skip to content

Commit 4c9a0ad

Browse files
committed
compiler-rt: avoid segfaults when re-exec'ing with ASLR
After 930a7c2 ("compiler-rt: re-exec with ASLR disabled when necessary") and 96fe7c8 ("compiler-rt: support ReExec() on FreeBSD"), binaries linked against the sanitizer libraries may segfault due to procctl(2) being intercepted. Instead, the non-intercepted internal_procctl() should be called. Similarly, the ReExec() function that re-executes the binary after turning off ASLR should not call elf_aux_info(3) and realpath(3), since these will also be intercepted. Instead, loop directly over the elf aux info vector to find the executable path, and avoid calling realpath(3) since it is actually unwanted for this use case. Fixes: 930a7c2, 96fe7c8 MFC after: 3 days
1 parent ecf2106 commit 4c9a0ad

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,7 @@ void CheckASLR() {
23232323
"and binaries compiled with PIE\n"
23242324
"ASLR will be disabled and the program re-executed.\n");
23252325
int aslr_ctl = PROC_ASLR_FORCE_DISABLE;
2326-
CHECK_NE(procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1);
2326+
CHECK_NE(internal_procctl(P_PID, 0, PROC_ASLR_CTL, &aslr_ctl), -1);
23272327
ReExec();
23282328
}
23292329
# elif SANITIZER_PPC64V2

contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
// that, it was never implemented. So just define it to zero.
5757
#undef MAP_NORESERVE
5858
#define MAP_NORESERVE 0
59+
extern const Elf_Auxinfo *__elf_aux_vector;
5960
#endif
6061

6162
#if SANITIZER_NETBSD
@@ -947,11 +948,11 @@ void ReExec() {
947948
const char *pathname = "/proc/self/exe";
948949

949950
#if SANITIZER_FREEBSD
950-
char exe_path[PATH_MAX];
951-
if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) {
952-
char link_path[PATH_MAX];
953-
if (realpath(exe_path, link_path))
954-
pathname = link_path;
951+
for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
952+
if (aux->a_type == AT_EXECPATH) {
953+
pathname = static_cast<const char *>(aux->a_un.a_ptr);
954+
break;
955+
}
955956
}
956957
#elif SANITIZER_NETBSD
957958
static const int name[] = {

0 commit comments

Comments
 (0)