openvmm: virtiofs: microVM aggregate file child accepts bare relative paths and symlinks in identity validation but fails in open_microvm_volume
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 63/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- operating-systems
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Rust
- Stelle
- 848
- Fork
- 63
- Merge medio
- 12h 32m
- PR unite (30g)
- 602
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/nvx
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesApertaarea: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/nvx#1632 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
microsoft/nvx#1628 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
microsoft/nvx#1629 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
microsoft/nvx#1631 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/nvx#1626 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/nvx
Issue simili
-
ai_p2
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
ClickHouse/ClickHouse#132519 ·
I maintainer di solito rispondono entro 1 giorno
-
Pattern-clip compiler tests miss the clip cap, sort order, muted output and count/emit agreementApertaarea: engine type: test
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
YuriiMurha/grooviq#224 ·
I maintainer di solito rispondono entro 1 giorno
-
state:needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
zed-industries/zed#67109 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
storytold/photocraft#15500 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno