Skip to content

Commit 9f0e180

Browse files
committed
Link shared sanitizer runtime with libresolv for dn_expand
Since the interceptor was added in 1a729bc, a process using sanitizers might need libresolv for the real version of __dn_expand. The linker flag for the static runtime was added in 6dce56b. But the dynamic runtime didn't get the dependency. This can cause crashes even when libresolv is not used directly, because it is also used by DNS lookups via e.g. getaddrinfo when the DNS reply uses compression. We observed the issue with the address sanitizer, but a quick look into the shared runtime libraries revealed that the memprof and tsan runtimes also export dn_expand and should thus be prone to the same issue. It should be mentioned that glibc plans to move libresolv into libc, which was partially completed in version 2.34 with the move of dn_comp and dn_expand. However, that is not an issue here: once the move is complete, there will only be a static libresolv.a stub left and so building against a version after the move will no longer produce a runtime dependency to libresolv.so. Fixes #59007.
1 parent e8c07f7 commit 9f0e180

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV)
189189
# Libraries.
190190
check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
191191
check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
192+
check_library_exists(resolv dn_expand "" COMPILER_RT_HAS_LIBRESOLV)
192193
check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
193194
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
194195
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)

compiler-rt/lib/asan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS)
153153
append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
154154
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
155155
append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
156+
append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv ASAN_DYNAMIC_LIBS)
156157
append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
157158

158159
# Compile ASan sources into an object library.

compiler-rt/lib/memprof/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS)
7474
append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS)
7575
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS)
7676
append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS)
77+
append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv MEMPROF_DYNAMIC_LIBS)
7778

7879
# Compile MemProf sources into an object library.
7980

compiler-rt/lib/tsan/rtl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(TSAN_DYNAMIC_LINK_LIBS
2020
append_list_if(COMPILER_RT_HAS_LIBDL dl TSAN_DYNAMIC_LINK_LIBS)
2121
append_list_if(COMPILER_RT_HAS_LIBM m TSAN_DYNAMIC_LINK_LIBS)
2222
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread TSAN_DYNAMIC_LINK_LIBS)
23+
append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv TSAN_DYNAMIC_LIBS)
2324

2425
set(TSAN_SOURCES
2526
tsan_debugging.cpp

0 commit comments

Comments
 (0)