Skip to content

Skip non-regular files in tryResolveLibrary#108

Open
arcusbuilds wants to merge 1 commit into
NVIDIA:mainfrom
arcusbuilds:fix-tryresolvelibrary-directory-shadowing
Open

Skip non-regular files in tryResolveLibrary#108
arcusbuilds wants to merge 1 commit into
NVIDIA:mainfrom
arcusbuilds:fix-tryresolvelibrary-directory-shadowing

Conversation

@arcusbuilds

Copy link
Copy Markdown

tryResolveLibrary returns the first candidate that filepath.EvalSymlinks resolves. EvalSymlinks succeeds for anything that exists, directories included, so a stray directory named after the library in an early search path (for example an empty /usr/lib64/libnvidia-ml.so.1 on an Ubuntu host) shadows the real library in a later one, and the dlopen that follows fails.

With this change, resolution skips any candidate that does not resolve to a regular file and keeps searching, falling back to the documented behavior of returning the library name as is.

The added test covers the shadowing scenario plus the happy path and the fallback paths. The shadowing and directories-only cases fail without the fix.

This is the same bug fixed in kubernetes-sigs/dra-driver-nvidia-gpu#1275, which carries a copy of this discovery code.

Fixes #107

tryResolveLibrary validated candidates with filepath.EvalSymlinks, which
succeeds for any existing path, including directories. Since candidates
are returned on first match and /usr/lib64 is searched before
/usr/lib/x86_64-linux-gnu, a stray directory named after the library in
/usr/lib64 shadows the real library in a later search path and the
resolved path fails to dlopen.

Skip any candidate that does not resolve to a regular file so resolution
continues through the remaining search paths, falling back to returning
the library name as is.

Signed-off-by: Srijan Keshri <srijan.keshri007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

info: tryResolveLibrary can return a directory, breaking library discovery

1 participant