Skip to content

Adds Vulkan ICD JSON file automatically if available#12818

Open
luiscape wants to merge 1 commit intogoogle:masterfrom
luiscape:luis/add-nvidia-icd-json
Open

Adds Vulkan ICD JSON file automatically if available#12818
luiscape wants to merge 1 commit intogoogle:masterfrom
luiscape:luis/add-nvidia-icd-json

Conversation

@luiscape
Copy link
Copy Markdown
Contributor

@luiscape luiscape commented Mar 30, 2026

Fixes: #12752

Attempts to reproduce the behavior of the nvidia container toolkit that injects the Vulkan IDC JSON file automatically. Also adds all other graphics files mimicking the toolkit implementation.

Assisted-by: Claude

for _, relPath := range allConfigs {
for _, searchPath := range searchPaths {
hostPath := path.Join(searchPath, relPath)
content, err := os.ReadFile(hostPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IIUC, what nvidia-container-toolkit seems to be doing is modifying the OCI spec and adding these mounts to the spec as read-only, so they will be bind-mounted into the container rootfs. We seem to be open-ing these files and writing them directly. Which I think is OK because:

  • It is difficult to inject mounts into the spec once we are this far in runsc initialization. Usually only the shim modifies the spec this way.
  • These files are likely small config files.

However, reading them from the host like this and pasting them into the container makes me a bit queasy. We should at least ensure that there are no symlinks. For example, a malicious container image can have a rootfs with /etc/vulkan/icd.d/nvidia_icd.json as a symlink to /etc/passwd or something, and the os.WriteFile() below will overwrite some host file (because symlinks will be resolved with host root, not container rootfs).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Regarding mount vs writing the files, do you want me to attempt a bind-mount? This seemed to be the smallest footprint. Otherwise I can think a bit about hardening this approach.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bind mounting is also susceptible to symlink attacks. But when we bind mount into rootfs in the gofer, we take a lot of care of symlinks and ensure that nothing escapes the rootfs into the host. See

gvisor/runsc/cmd/gofer.go

Lines 541 to 544 in dc29295

dst, err := resolveSymlinks(root, m.Destination)
if err != nil {
return fmt.Errorf("resolving symlinks to %q: %v", m.Destination, err)
}

I think a similar symlink-awareness would be nice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am now using resolveSymlinks to add these files. I moved the function to specutils.ResolveSymlinks to make it available everywhere, hence the many file edits. Let me know if this is alright.

@luiscape luiscape force-pushed the luis/add-nvidia-icd-json branch from 23295f9 to 6a3e30a Compare April 2, 2026 03:02
@luiscape luiscape force-pushed the luis/add-nvidia-icd-json branch from 6a3e30a to 0d0adf7 Compare April 3, 2026 21:29
@luiscape
Copy link
Copy Markdown
Contributor Author

luiscape commented Apr 3, 2026

Added a few missing config files. This fully replicates the expected behavior from the nvidia container toolkit.

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.

Gvisor doesn't inject the icd file for nvidia, as is done by nvidia container toolkit

2 participants