Skip to content

Skip non-regular files in tryResolveLibrary - #108

Merged
tariq1890 merged 1 commit into
NVIDIA:mainfrom
arcusbuilds:fix-tryresolvelibrary-directory-shadowing
Jul 30, 2026
Merged

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

Conversation

@arcusbuilds

Copy link
Copy Markdown
Contributor

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

@tariq1890

tariq1890 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Thanks @arcusbuilds !

Can you address the finding emitted by the DCO check?

Commit sha: [96c14b0](https://github.com/NVIDIA/go-nvlib/pull/108/commits/96c14b0e85de91c6f02f42045371c3e51fd0becc), Author: Srijan Keshri, Committer: Srijan Keshri; Expected "Srijan Keshri [srijankeshri007@gmail.com](mailto:srijankeshri007@gmail.com)", but got "Srijan Keshri [srijan.keshri007@gmail.com](mailto:srijan.keshri007@gmail.com)"

Can you also ensure that your commit is signed? See here for more details.

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 <srijankeshri007@gmail.com>
@arcusbuilds
arcusbuilds force-pushed the fix-tryresolvelibrary-directory-shadowing branch from 96c14b0 to 4521c9d Compare July 30, 2026 15:23
@arcusbuilds

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Both items are addressed and force-pushed:

  • DCO: the sign-off email now matches the author (srijankeshri007@gmail.com — the earlier mismatch was a stray dot).
  • The commit is now SSH-signed and shows as verified.

The test workflow hasn't run on this PR yet — it looks like it needs a maintainer to approve the run. Happy to make any other changes.

@rajathagasthya rajathagasthya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

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

3 participants