Skip to content

Conversation

@elezar
Copy link
Contributor

@elezar elezar commented Jun 19, 2025

This change ensures that the filemode for a CDI device is properly set from the host device node when adding devices to the CDI spec.

Without this the device node permissions are 000 in the container under certain conditions (such as Kata).

See also NVIDIA/nvidia-container-toolkit#960

@elezar elezar requested a review from klihub June 19, 2025 13:28
@elezar elezar self-assigned this Jun 19, 2025
@elezar elezar requested a review from zvonkok June 19, 2025 13:29
@elezar
Copy link
Contributor Author

elezar commented Jun 19, 2025

@zvonkok for the Kata use case the rust implementation must also be updated.

@elezar elezar force-pushed the add-extra-device-info branch from 4120810 to 8288672 Compare June 19, 2025 13:36
@klihub klihub requested a review from bart0sh June 23, 2025 06:38
}

if d.Type != "" && (d.Major != 0 || d.Type == "p") {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also set d.FileMode here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would you set it to in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

The same as below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is an early return meaning that we don't query the device node. I can make things a bit more consistent though. Let me see what I can come up with.

d.FileMode = &di.fileMode
}

if d.Type == "p" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if d.Type == "p" {
if d.Type == fifoDevice {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use "p" elsewhere in this function. I don't mind changing this to a constant, but would do so consistently across this function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please do.

@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. This PR will be closed in 30 days unless new comments are made or the stale label is removed. To skip these checks, apply the "lifecycle/frozen" label.

@bart0sh
Copy link
Contributor

bart0sh commented Nov 23, 2025

@elezar There are a couple of seemingly not yet addressed review comments in this PR. Should we wait until they're addressed or proceed to merge this PR as is?

This change ensures that the filemode for a CDI device is
properly set from the host device node when adding devices
to the CDI spec.

Without this the device node permissions are 000 in the container
under certain conditions (such as Kata).

Signed-off-by: Evan Lezar <[email protected]>
@elezar elezar force-pushed the add-extra-device-info branch from 8288672 to 457489d Compare November 24, 2025 14:10
@elezar
Copy link
Contributor Author

elezar commented Nov 24, 2025

@bart0sh I have revisted this PR and hopefully addressed your comments.

Copy link
Contributor

@bart0sh bart0sh left a comment

Choose a reason for hiding this comment

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

/lgtm

@bart0sh
Copy link
Contributor

bart0sh commented Nov 24, 2025

@klihub Can you take a look at the latest changes and merge if everything is ok?

Comment on lines +100 to +102
// Even for minimally-specified device nodes, we update the file mode if
// required. This is useful for rootless containers where device node
// requests may be treated as bind mounts.
Copy link
Contributor

@klihub klihub Nov 24, 2025

Choose a reason for hiding this comment

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

@elezar A question related to me trying to understand the essence of that comment better. If we have a rootless container, where IIUC devices are bind-mounted into the container instead of being mknod'ded, will the devices not always end up with the permissions of the bind-mounted device on the host side ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I may have been mixing behaviour that I saw in another case. I will update the comment in a follow-up.

Copy link
Contributor

@klihub klihub left a comment

Choose a reason for hiding this comment

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

@elezar @bart0sh This looks good to me. I only have one question related to a comment in the code about rootless containers.

@klihub klihub merged commit 33b65b4 into cncf-tags:main Nov 25, 2025
8 checks passed
@elezar elezar deleted the add-extra-device-info branch November 25, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants