Search the calling image's RUNPATH for dlopen from loaded code - #4
Open
Nikita-prog-art wants to merge 1 commit into
Open
Search the calling image's RUNPATH for dlopen from loaded code#4Nikita-prog-art wants to merge 1 commit into
Nikita-prog-art wants to merge 1 commit into
Conversation
glibc resolves a bare dlopen name through the calling object's DT_RUNPATH (or its DT_RPATH when it carries no RUNPATH). SoLo consulted the requester's paths only while resolving its DT_NEEDED entries, so a dlopen issued by loaded code could not reach a sibling through $ORIGIN. On WSL2, dzn's D3D12 UMD fails to load its libigd12um64xel.so exactly this way and previously required DL_ELF_LIBRARY_PATH pointed at the driver directory. Map the glibc-boundary caller's return address to the issuing image, thread it into Loader::load, and let resolvePath use it for the rpath/runPath slots, in glibc's order. Register dlopen@GLIBC_2.2.5 in the shim table as well: pre-2.34 importers previously fell through to the raw stub and skipped the caller plumbing. The smoke test builds a host DSO with -rpath '$ORIGIN/runpath' - and an old-dtags DT_RPATH variant - that dlopens a sibling by bare name from a directory no other search path carries, so the load succeeds only through the caller's path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
glibc resolves a bare
dlopenname through the calling object'sDT_RUNPATH(or itsDT_RPATHwhen it carries no RUNPATH). SoLo consulted the requester's paths only while resolving that image's ownDT_NEEDEDentries, so adlopenissued by loaded code could not reach a sibling through$ORIGIN.On WSL2 this breaks dzn: the D3D12 runtime loads
libigd12umd64.sofrom the kernel-provided absolute path, and that image then dlopenslibigd12um64xel.soby bare name from its own directory. The load previously requiredDL_ELF_LIBRARY_PATHpointed at the Intel driver directory. Two details made it worse: the UMD importsdlopen@GLIBC_2.2.5, which was not in the shim table and fell through to the raw stub, skipping the glibc-semantics wrapper entirely.Fix
sh_glibc_dlopen/sh_glibc_dlmopenare now noinline boundary entries that capture__builtin_return_address(0); the newstub_dlopen_from→ElfImage::loadElfFrompath maps that address to the issuing image viaLoader::findImageByAddressand threads it intoLoader::load.resolvePathtakes the dlopen caller and uses it for the rpath/runPath slots in glibc's order (DT_RPATHbeforeLD_LIBRARY_PATHwhen the caller has no RUNPATH,DT_RUNPATHafter it), falling back to the in-flight requester forDT_NEEDEDresolution.dlopen@GLIBC_2.2.5is registered in the shim table next toGLIBC_2.34.Test
The smoke test builds a host DSO with
-Wl,-rpath,'$ORIGIN/runpath'— and an old-dtagsDT_RPATHvariant — that dlopens a sibling by bare name from a directory no other search path carries, so the load succeeds only through the caller's path. Both checks fail withcaller DT_RUNPATH lookup failed/caller DT_RPATH lookup failedbefore the fix.Verification
./build testpasses on Debian (host gcc 14.2); the new checks fail when the loader change is reverted../build vulkan,--driver dzn_icd.json) now runs with an empty environment: noDL_ELF_LIBRARY_PATH, noLD_LIBRARY_PATH— the UMD resolves through its caller's RUNPATH and the WSL client libraries through/etc/ld.so.cache.