-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link shared sanitizer runtime with libresolv for dn_expand #116415
Conversation
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 llvm#59007.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other sanitizers?
@llvm/pr-subscribers-compiler-rt-sanitizer @llvm/pr-subscribers-pgo Author: Aaron Puchert (aaronpuchert) ChangesSince 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. Full diff: https://github.com/llvm/llvm-project/pull/116415.diff 4 Files Affected:
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 6d52eecc9a91fe..74f7fb4ac4880f 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -189,6 +189,7 @@ check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV)
# Libraries.
check_library_exists(dl dlopen "" COMPILER_RT_HAS_LIBDL)
check_library_exists(rt shm_open "" COMPILER_RT_HAS_LIBRT)
+check_library_exists(resolv dn_expand "" COMPILER_RT_HAS_LIBRESOLV)
check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index fb3d74283a61e0..7a92a1a187a816 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -153,6 +153,7 @@ append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
+append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv ASAN_DYNAMIC_LIBS)
append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
# Compile ASan sources into an object library.
diff --git a/compiler-rt/lib/memprof/CMakeLists.txt b/compiler-rt/lib/memprof/CMakeLists.txt
index e6d99daca6ee7d..2d0df65f43a260 100644
--- a/compiler-rt/lib/memprof/CMakeLists.txt
+++ b/compiler-rt/lib/memprof/CMakeLists.txt
@@ -74,6 +74,7 @@ append_list_if(COMPILER_RT_HAS_LIBRT rt MEMPROF_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBM m MEMPROF_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread MEMPROF_DYNAMIC_LIBS)
append_list_if(COMPILER_RT_HAS_LIBLOG log MEMPROF_DYNAMIC_LIBS)
+append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv MEMPROF_DYNAMIC_LIBS)
# Compile MemProf sources into an object library.
diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
index f40e72dbde1f98..a6e9c7960fd594 100644
--- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt
+++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt
@@ -20,6 +20,7 @@ set(TSAN_DYNAMIC_LINK_LIBS
append_list_if(COMPILER_RT_HAS_LIBDL dl TSAN_DYNAMIC_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBM m TSAN_DYNAMIC_LINK_LIBS)
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread TSAN_DYNAMIC_LINK_LIBS)
+append_list_if(COMPILER_RT_HAS_LIBRESOLV resolv TSAN_DYNAMIC_LIBS)
set(TSAN_SOURCES
tsan_debugging.cpp
|
I based it on this:
But this might be due to my build settings. |
For HwASan, I have For NSan the library should never be relevant. There is no floating-point in DNS. The UBSan runtime doesn't intercept any functions, it only consists of error handlers. |
One more: MSan does not seem to offer a shared runtime. |
RTSan has a shared runtime only on Mac, i.e. My understanding is that at least |
Maybe as alternative solution we convert this into MSAN-only interceptor and avoid linking more stuff into asan? |
The interceptors are definitely tailored towards MSan, where they're necessary to address false positives. They don't even check for reads, just register the writes. But I'm not sure where to disable it. HWASan has hwasan_platform_interceptors.h, where lots of interceptors are disabled, but I can't find an equivalent place for ASan. The additional link dependency might also be temporary: my impression is that glibc wants to integrate all sublibraries into the main library. |
I would suspect these calls ( "blocking" in the case of rtsan means unsafe for real-time code (contains a syscall of any type). I would guess that any query to the DNS subsystem results in a system call. |
My understanding is that they don't do any syscalls, they just "compress" or "expand" domain names for a DNS query or reply. Since they write into buffers allocated by the caller, I think they don't even do any allocations. But I didn't check this hypothesis. |
@vitalybuka, I forgot to mention that we already link with But I have no issue with disabling the interceptor for the address sanitizer, I'm just not sure where to put that yet. |
They need to be moved from sanitizer_common into msan_iterceptors |
One reason why it might have ended up in the common interceptors is this comment in // FIXME: move as many interceptors as possible into
// sanitizer_common/sanitizer_common_interceptors.h I have no problem with moving in the opposite direction, but maybe this comment should be removed? Maybe interceptors should only move into the common area if they're actually interesting for multiple sanitizers? |
yes, this does not look relevant to me |
Posted the move as separate pull request #119071, will close this change if that is approved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we go with another one
We decided to move the interceptors to MSan instead, so this change is no longer needed. |
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.