Skip to content

devices/fs: fix set_creds not switching credentials when CAP_SET{U,G}ID is available#668

Draft
nikromen wants to merge 1 commit intocontainers:mainfrom
nikromen:fix-virtiofs-set-creds-userns
Draft

devices/fs: fix set_creds not switching credentials when CAP_SET{U,G}ID is available#668
nikromen wants to merge 1 commit intocontainers:mainfrom
nikromen:fix-virtiofs-set-creds-userns

Conversation

@nikromen
Copy link
Copy Markdown

@nikromen nikromen commented May 6, 2026

When the VMM process runs as non-root but retains CAP_SETUID/CAP_SETGID (e.g. in a user namespace with --userns=keep-id), set_creds() skipped the credential switch for uid/gid 0 because the uid == 0 check came before the capability check. This caused all guest root file operations to execute with the VMM's actual uid/gid, leading to EPERM on writes to root-owned directories.

Reorder the conditions so that when we have the capability to switch credentials, we always do so... including for uid/gid 0.

Reproducer (on fedora-43 x86):

podman run --rm --privileged --runtime krun --userns=keep-id fedora:latest dnf install -y htop

Fails with "Cannot open log file: (13) - Permission denied [/var/log/dnf5.log]". Any guest root file operation returns EPERM.

…ID is available

When the VMM process runs as non-root but retains CAP_SETUID/CAP_SETGID
(e.g. in a user namespace with --userns=keep-id), set_creds() skipped
the credential switch for uid/gid 0 because the `uid == 0` check came
before the capability check. This caused all guest root file operations
to execute with the VMM's actual uid/gid, leading to EPERM on writes to
root-owned directories.

Reorder the conditions so that when we have the capability to switch
credentials, we always do so... including for uid/gid 0.
Copy link
Copy Markdown
Member

@jakecorrenti jakecorrenti left a comment

Choose a reason for hiding this comment

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

Please make sure that you sign your commits. You can fix it by doing git commit --amend -s

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.

2 participants