openvmm: virtiofs: microVM aggregate file child accepts bare relative paths and symlinks in identity validation but fails in open_microvm_volume
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 63/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- operating-systems
Research direction
Start in vm/devices/virtio/virtiofs/src/microvm/fs.rs at open_microvm_volume to see how root_path.parent() and file_name() are split before mount_options.new_volume(directory), then compare with microvm_object_identity and validate_object_path in vm/devices/virtio/virtiofs/src/microvm/profile.rs, which canonicalize first. Reproduce both cases (bare seed.txt and a symlink to a regular file) in a temp directory and run the virtiofs tests. Done means identity validation and volume opening agree on one policy for relative paths and symlinks, with a regression test covering both.
Written by the indexing model from the issue text.
Description
Summary
For a microVM aggregate single-file child (MicroVmAggregateChild::new_file), microvm_file_identity and MicroVmAggregateChild::validate_root_path canonicalize root_path before checking that it names a regular file, whereas open_microvm_volume splits the uncanonicalized root_path via root_path.parent() and root_path.file_name(). Because of this mismatch, both (a) a bare relative filename such as Path::new("seed.txt") and (b) a symlink pointing to a regular file pass microvm_file_identity and validate_root_path, yet fail mid-attachment inside open_microvm_volume. Found by testing.
Root Cause
In vm/devices/virtio/virtiofs/src/microvm/profile.rs#L667-L690 (called by microvm_file_identity and via validate_root_path / validate_object_path), microvm_object_identity calls std::fs::canonicalize(path)? first, resolving relative paths against the current working directory and following symlinks to their final regular-file target. However, when VirtioFs::new_microvm_aggregate opens the child volume in open_microvm_volume, it decomposes the caller's raw root_path without normalizing or canonicalizing it:
let (Some(directory), Some(name)) = (root_path.parent(), root_path.file_name()) else {
anyhow::bail!(
"microVM virtio-fs file {} has no host directory",
root_path.display()
);
};
let exposed_file = PathBuf::from(name);
...
let volume = mount_options.new_volume(directory)?;
This creates two concrete failures for inputs accepted by microvm_file_identity and child.validate_root_path(root_path):
- Bare relative filenames (
Path::new("seed.txt")): In Rust'sstd::path::Path,Path::new("seed.txt").parent()returnsSome(Path::new(""))rather thanNoneorSome(Path::new(".")).open_microvm_volumepasses""tomount_options.new_volume(""), which fails to open the host directory withENOENTinstead of opening"."(unlike directory shares, wherePath::new("work")is passed directly or"./seed.txt"yieldsparent() == Some(Path::new("."))). - Symlinks to regular files:
microvm_file_identityandvalidate_root_pathcanonicalize the symlink and succeed on the target regular file, whereasopen_microvm_volumeopens the symlink's parent directory and setsexposed_fileto the symlink's basename.VirtioFsInode::newthen callsvolume.lstat(&path)(O_NOFOLLOW), observingS_IFLNKinstead ofS_IFREG, and fails inVirtioFsVolume::ensure_object_allowedwithEACCES(andvalidate_opened_rootalso requireslx::S_IFREG).
Consequence
Callers that compute microvm_file_identity and pass MicroVmAggregateChild::validate_root_path for either a bare relative filename in the working directory ("seed.txt", whereas "./seed.txt" works) or a host symlink to a regular file (whereas directory shares follow a symlink at root_path when opening the root directory) hit unexpected ENOENT or EACCES failures during VirtioFs::new_microvm_aggregate.
Reproduction
- Bare relative path: In a temporary working directory containing
seed.txt, build aMicroVmAggregateChild::new_file("seed".to_owned(), microvm_file_identity("seed.txt")?, true)and callVirtioFs::new_microvm_aggregate(&[Path::new("seed.txt")], profile). Observevalidate_root_pathsucceed andnew_microvm_aggregatefail withENOENTonnew_volume(""). - Symlink path: Create a regular file
real.txtand a symlinklink.txt -> real.txt, computemicrovm_file_identity(&link)(which succeeds), and callVirtioFs::new_microvm_aggregate(&[&link], profile). Observevalidate_root_pathsucceed andopen_microvm_volumefail withEACCESwhenVirtioFsInode::newlstatslink.txt.
Suggested Fix
First, in open_microvm_volume, substitute Path::new(".") whenever directory.as_os_str().is_empty() so bare relative filenames open the current working directory consistently with "./file". Second, align profile validation and volume opening on a single policy for symlink root_paths on file children: either reject symlinks up front in microvm_file_identity / validate_object_path (inspecting std::fs::symlink_metadata(path) before canonicalizing) if file-child host paths must directly name regular files, or canonicalize root_path in open_microvm_volume before splitting (parent, file_name) so a symlink root_path opens the target regular file's parent directory and exposes the target's basename (matching how directory shares resolve a symlink at the share root).
Related: #1614.
- Dominant language
- Rust
- Stars
- 848
- Forks
- 63
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 571
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/nvx
-
area: ci
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area: ci
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesOpenarea: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/nvx#1632 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/nvx#1628 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
microsoft/nvx#1629 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
community differential help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
hffgzktbcc-blip/ounce-core#489 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
pact-foundation/pact-plugins#125 ·
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jolars/panache#627 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
facebookexperimental/hermit#347 ·
Maintainers usually reply within 1 day