Skip to content

Commit 8434e5d

Browse files
committed
[dfsan] Don't clear shadow on dlopen(NULL, flags)
This ports msan https://reviews.llvm.org/D14795 to dfsan. dfsan, like msan, clears shadow for globals in a newly opened DSO in case the DSO occupies the address of a previously labeled/poisoned area. The operation should not happen on the main executable. In addition, for a DT_EXEC executable, l_addr is zero and will lead to a null pointer dereference in ForEachMappedRegion.
1 parent 184c22d commit 8434e5d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler-rt/lib/dfsan/dfsan_custom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ __dfsw_dlopen(const char *filename, int flag, dfsan_label filename_label,
842842
dfsan_label flag_label, dfsan_label *ret_label) {
843843
void *handle = dlopen(filename, flag);
844844
link_map *map = GET_LINK_MAP_BY_DLOPEN_HANDLE(handle);
845-
if (map)
845+
if (filename && map)
846846
ForEachMappedRegion(map, dfsan_set_zero_label);
847847
*ret_label = 0;
848848
return handle;

compiler-rt/test/dfsan/custom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
22
// RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
33
// RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-combine-pointer-labels-on-load=false -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
4-
// RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-combine-pointer-labels-on-load=false %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
4+
// RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-combine-pointer-labels-on-load=false -no-pie %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
55
//
66
// Tests custom implementations of various glibc functions.
77

0 commit comments

Comments
 (0)