summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-11-19 00:55:45 +0000
committerReid Kleckner <rnk@google.com>2015-11-19 00:55:45 +0000
commit4029426b17e1d4c2ceed61cb086954b60a38eae9 (patch)
tree478ff5e165f3826830b494387fa20c484b08d237
parent3afb80e375c97b01f05942ae5e5127babc962fa6 (diff)
downloadbcm5719-llvm-4029426b17e1d4c2ceed61cb086954b60a38eae9.tar.gz
bcm5719-llvm-4029426b17e1d4c2ceed61cb086954b60a38eae9.zip
[msan] Don't unpoison phdrs on dlopen(NULL, 0)
Summary: dlopen(NULL, ...) is intended to give you back a handle to the executable for use with dlsym. Casting it to link_map and using it with ForEachMappedRegion results in a crash. We also shouldn't unpoison the globals of a DSO that is already in memory. This ensures that we don't do it for the executable, but in general, MSan may have false negatives if the DSO is already loaded. Reviewers: eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14795 llvm-svn: 253530
-rw-r--r--compiler-rt/lib/msan/msan_interceptors.cc9
-rw-r--r--compiler-rt/test/msan/dlopen_executable.cc17
2 files changed, 22 insertions, 4 deletions
diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc
index 1bf196ecdbe..fc28e080f26 100644
--- a/compiler-rt/lib/msan/msan_interceptors.cc
+++ b/compiler-rt/lib/msan/msan_interceptors.cc
@@ -1434,10 +1434,11 @@ int OnExit() {
} while (false) // FIXME
#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
-#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) \
- do { \
- link_map *map = GET_LINK_MAP_BY_DLOPEN_HANDLE((handle)); \
- if (map) ForEachMappedRegion(map, __msan_unpoison); \
+#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle) \
+ do { \
+ link_map *map = GET_LINK_MAP_BY_DLOPEN_HANDLE((handle)); \
+ if (filename && map) \
+ ForEachMappedRegion(map, __msan_unpoison); \
} while (false)
#define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end) \
diff --git a/compiler-rt/test/msan/dlopen_executable.cc b/compiler-rt/test/msan/dlopen_executable.cc
new file mode 100644
index 00000000000..ac8a14b9407
--- /dev/null
+++ b/compiler-rt/test/msan/dlopen_executable.cc
@@ -0,0 +1,17 @@
+// RUN: %clangxx_msan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdlib.h>
+
+static int my_global;
+
+int main(void) {
+ int *uninit = (int*)malloc(sizeof(int));
+ my_global = *uninit;
+ void *p = dlopen(0, RTLD_NOW);
+ assert(p && "failed to get handle to executable");
+ return my_global;
+ // CHECK: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: #0 {{.*}} in main{{.*}}dlopen_executable.cc:[[@LINE-2]]
+}
OpenPOWER on IntegriCloud