From 5829c4a87c88e634dbec03ce87a9f8d5cd6c1b81 Mon Sep 17 00:00:00 2001 From: Derek Bruening Date: Thu, 22 Aug 2019 17:12:23 -0400 Subject: [PATCH] i#3799: Fix leak and false trigger on DR reload Adds ignoring of kernels labeling DR's .bss as "[heap]", to avoid unnecessary reloading at startup. Fixes failures to unmap the executable's headers on a reload. Fixes #3799 --- core/unix/loader.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/unix/loader.c b/core/unix/loader.c index 6df9877fb89..edaaf4fe969 100644 --- a/core/unix/loader.c +++ b/core/unix/loader.c @@ -1629,6 +1629,8 @@ dynamorio_lib_gap_empty(void) while (memquery_iterator_next(&iter) && iter.vm_start < dr_end) { if (iter.vm_start >= dr_start && iter.vm_end <= dr_end && iter.comment[0] != '\0' && + /* i#3799: ignore the kernel labeling DR's .bss as "[heap]". */ + strcmp(iter.comment, "[heap]") != 0 && strcmp(iter.comment, dynamorio_library_path) != 0) { /* There's a non-anon mapping inside: probably vvar and/or vdso. */ res = false; @@ -1877,6 +1879,7 @@ privload_early_inject(void **sp, byte *old_libdr_base, size_t old_libdr_size) /* i#1227: on a conflict with the app (+ room for the brk): reload ourselves */ if (get_dynamorio_dll_start() < exe_end + APP_BRK_GAP && get_dynamorio_dll_end() > exe_map) { + elf_loader_destroy(&exe_ld); reload_dynamorio(sp, exe_map, exe_end + APP_BRK_GAP); ASSERT_NOT_REACHED(); } @@ -1887,6 +1890,7 @@ privload_early_inject(void **sp, byte *old_libdr_base, size_t old_libdr_size) * very often. */ if (!dynamorio_lib_gap_empty()) { + elf_loader_destroy(&exe_ld); reload_dynamorio(sp, get_dynamorio_dll_start(), get_dynamorio_dll_end()); ASSERT_NOT_REACHED(); }