From 44fcff0f433b8267869ddd31b99d7067a0b57ae6 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkarov Date: Mon, 17 Jun 2019 20:27:16 +0300 Subject: [PATCH] New sanitizer option to disable dlclose processing This is a simple workaround for https://github.com/google/sanitizers/issues/89: Avoid frames for functions from unloaded shared library. Rtld will unload dynamically loaded shared objects, we are not preventing unloading in this, just deferring it. This could hide potential bugs like accesing library range addressing after dlclose or some tricky cases for functions with __attribute__((__destructor__)) + code that relies on explicit call to dlclose. Change-Id: I14fb2b8846350e07040d6f9215b936d9b2956faa Signed-off-by: Mikhail Kashkarov --- libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc | 4 ++++ libsanitizer/sanitizer_common/sanitizer_flags.inc | 3 +++ 2 files changed, 7 insertions(+) diff --git a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc index e8cee58..f652db3 100644 --- a/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc +++ b/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc @@ -6016,6 +6016,10 @@ INTERCEPTOR(void*, dlopen, const char *filename, int flag) { } INTERCEPTOR(int, dlclose, void *handle) { + // Do not call dlclose to keep mapped memory ranges information to avoid + // frames. + if (common_flags()->no_dlclose) + return 0; void *ctx; MAYBE_FORWARD_TO_REAL(dlclose, handle); COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlclose, handle); diff --git a/libsanitizer/sanitizer_common/sanitizer_flags.inc b/libsanitizer/sanitizer_common/sanitizer_flags.inc index a80c993..a1086a7 100644 --- a/libsanitizer/sanitizer_common/sanitizer_flags.inc +++ b/libsanitizer/sanitizer_common/sanitizer_flags.inc @@ -245,6 +245,9 @@ COMMON_FLAG(bool, intercept_stat, true, COMMON_FLAG(bool, intercept_send, true, "If set, uses custom wrappers for send* functions " "to find more errors.") +COMMON_FLAG(bool, no_dlclose, false, + "If set, dlclose will not be executed to avoid " + "frames.") COMMON_FLAG(bool, decorate_proc_maps, false, "If set, decorate sanitizer " "mappings in /proc/self/maps with " "user-readable names") -- 2.7.4