Skip to content

Add override_stat xattr support for virtiofs mounts#64

Merged
JAORMX merged 1 commit intomainfrom
xattrs
Apr 8, 2026
Merged

Add override_stat xattr support for virtiofs mounts#64
JAORMX merged 1 commit intomainfrom
xattrs

Conversation

@jhrozek
Copy link
Copy Markdown
Contributor

@jhrozek jhrozek commented Apr 8, 2026

Summary

  • Add OverrideUID/OverrideGID fields to VirtioFSMount that set user.containers.override_stat xattrs on host directories before VM boot, making libkrun's virtiofs FUSE server report the desired UID/GID to the guest instead of the host user's
  • Add SetOverrideStatTree walker in internal/xattr that resolves symlinks at the root, skips symlink entries during traversal, and enforces path boundary checks to prevent setting xattrs outside the mount
  • Includes input validation for negative UIDs/GIDs, build-tagged no-op for unsupported platforms, and uses DirEntry.Info() to avoid redundant Lstat syscalls

Fixes the issue where workspace directories mounted via virtiofs on macOS appear with the host user's UID inside the guest VM, preventing the guest sandbox user from writing to mounted files.

Test plan

  • task fmt — clean
  • task lint — 0 issues
  • task test — all tests pass with race detector
  • Manual: tested through brood-box with a replace directive — guest sees correct ownership on virtiofs mounts

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Looked at this for correctness and OS portability (Linux + macOS). The implementation is solid. The walker, symlink handling, build tags, and boundary checks all work correctly on both platforms.

Left a few inline comments... the only actionable one is the OverrideUID doc comment which is a bit misleading about why UID 0 can't be used. The other two are just confirming the portability story checks out.

On macOS, workspace directories mounted via virtiofs appear with the
host user's UID inside the guest VM. This prevents the guest sandbox
user from writing to files and nested directories.

Add OverrideUID/OverrideGID fields to VirtioFSMount and a new
SetOverrideStatTree function that walks the mount path and sets
user.containers.override_stat xattrs on all files and directories
before VM boot. This makes libkrun's virtiofs FUSE server report the
desired UID/GID to the guest. Symlinks are skipped to prevent setting
xattrs outside the mount boundary.

Includes input validation for negative UIDs/GIDs and orphaned
OverrideGID, build-tagged no-op stub for unsupported platforms,
and performance optimization using DirEntry.Info() to avoid
redundant Lstat syscalls during the tree walk.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JAORMX JAORMX merged commit db5b591 into main Apr 8, 2026
7 checks passed
@JAORMX JAORMX deleted the xattrs branch April 8, 2026 12:46
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