You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openvmm: virtiofs: microVM aggregate file child with ':' or '\' in host filename attaches successfully but fails every guest lookup with EINVAL #1614
When attaching a single-file share to a microVM aggregate via VirtioFs::new_microvm_aggregate, if the backing host file's basename contains : or \ (valid POSIX filename bytes on Linux/Unix, even when the guest-visible child share name itself is plain, e.g. "f"), attachment succeeds without error, but every subsequent guest FUSE_LOOKUP or FUSE_READDIRPLUS for that share fails with EINVAL. Found by testing (also blocks formal verification).
Root Cause
In vm/devices/virtio/virtiofs/src/microvm/fs.rs#L164-L177, open_microvm_volume opens a file child's parent directory as a strict microVM volume whose exposed_file (volume.root_entry()) is set to the host file's basename (root_path.file_name()), and constructs SubtreePolicy::new directly, bypassing parse_policy_paths (which rejects \0, \, and :):
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 policy = SubtreePolicy::new(vec![PathBuf::new()],vec![exposed_file.clone()],Vec::new(),
read_only,)?;
Host orchestration attaching a Linux file whose basename contains : (common in timestamps, PCI/device identifiers, OCI digests, or systemd-style names) or \ under a clean guest share name receives Ok(VirtioFs) at VM startup, leaving the share listed in plain READDIR (DT_REG) yet permanently unreachable (EINVAL on LOOKUP and READDIRPLUS) inside the guest.
Reproduction
On Unix, create a regular file whose basename contains : or \ (for example dir.path().join("a:b")).
Build a MicroVmAggregateChild::new_file("f".to_owned(), microvm_file_identity(&host_file)?, true) and attach it with VirtioFs::new_microvm_aggregate(&[&host_file], profile).
Observe new_microvm_aggregate succeed, then call Fuse::lookup(&fs, &request(FUSE_ROOT_ID), LxStr::from_bytes(b"f")) and observe Err(lx::Error::EINVAL).
In open_microvm_volume, validate that name.as_encoded_bytes() contains neither b'\\' nor b':' (returning an anyhow error before opening the volume) whenever file is true, so host filenames incompatible with strict microVM alias validation are rejected up front at attachment time rather than failing at guest lookup time.
diff --git a/vm/devices/virtio/virtiofs/src/microvm/fs.rs b/vm/devices/virtio/virtiofs/src/microvm/fs.rs
index 067e1ae40..1004726ba 100644
--- a/vm/devices/virtio/virtiofs/src/microvm/fs.rs+++ b/vm/devices/virtio/virtiofs/src/microvm/fs.rs@@ -167,6 +167,14 @@ fn open_microvm_volume(
root_path.display()
);
};
+ // Strict microVM volumes reject alias components containing `\` or `:`+ // (`validate_relative_path`), so refuse unrepresentable host filenames+ // before opening the volume.+ let name_bytes = name.as_encoded_bytes();+ anyhow::ensure!(+ !name_bytes.contains(&b'\\') && !name_bytes.contains(&b':'),+ "a microVM virtio-fs file child's host file name has a `\\` or `:`"+ );
let exposed_file = PathBuf::from(name);
let policy = SubtreePolicy::new(
vec![PathBuf::new()],
diff --git a/vm/devices/virtio/virtiofs/tests/file_child_share_name.rs b/vm/devices/virtio/virtiofs/tests/file_child_share_name.rs
new file mode 100644
index 000000000..3d49bfaee
--- /dev/null+++ b/vm/devices/virtio/virtiofs/tests/file_child_share_name.rs@@ -0,0 +1,87 @@+// Copyright (c) Microsoft Corporation.+// Licensed under the MIT License.++//! Tests that a microVM aggregate file child whose host filename contains `:`+//! or `\` is rejected during attachment rather than attaching an unreachable+//! share whose lookups fail with `EINVAL`.++use fuse::Fuse;+use fuse::Request;+use fuse::protocol::FUSE_LOOKUP;+use fuse::protocol::FUSE_ROOT_ID;+use fuse::protocol::fuse_in_header;+use lx::LxStr;+use tempfile::tempdir;+use test_with_tracing::test;+use virtiofs::VirtioFs;+use virtiofs::profile::MICROVM_ATTACHMENT_ID;+use virtiofs::profile::MicroVmAggregateChild;+use virtiofs::profile::MicroVmVirtioFsProfile;+use virtiofs::profile::microvm_file_identity;+use zerocopy::IntoBytes;++fn request(opcode: u32, nodeid: u64) -> Request {+ let header = fuse_in_header {+ len: size_of::<fuse_in_header>() as u32,+ opcode,+ unique: 1,+ nodeid,+ uid: 0,+ gid: 0,+ pid: 1,+ padding: 0,+ };+ Request::new(header.as_bytes()).unwrap()+}++/// Attaches a file child backed by `host_name` under guest share name `"f"`:+/// either attachment fails up front, or guest lookup of `"f"` resolves to the+/// regular file. Returns whether attachment succeeded.+fn created_and_reachable(host_name: &str) -> bool {+ let dir = tempdir().unwrap();+ let host_file = dir.path().join(host_name);+ std::fs::write(&host_file, b"x").unwrap();+ let child = MicroVmAggregateChild::new_file(+ "f".to_owned(),+ microvm_file_identity(&host_file).unwrap(),+ true,+ )+ .unwrap();+ let profile =+ MicroVmVirtioFsProfile::from_aggregate(MICROVM_ATTACHMENT_ID.to_owned(), vec![child])+ .unwrap();+ let Ok(fs) = VirtioFs::new_microvm_aggregate(&[&host_file], profile) else {+ return false;+ };+ let entry = Fuse::lookup(+ &fs,+ &request(FUSE_LOOKUP, FUSE_ROOT_ID),+ LxStr::from_bytes(b"f"),+ )+ .unwrap_or_else(|e| panic!("{host_name:?}: a created file child must be reachable: {e:?}"));+ assert_eq!(entry.attr.mode & lx::S_IFMT, lx::S_IFREG);+ true+}++/// A host filename containing `:` or `\` cannot be stored as a strict microVM+/// alias path, so `VirtioFs::new_microvm_aggregate` must refuse attachment up+/// front rather than creating an unreachable child.+#[cfg(unix)]+#[test]+fn file_child_whose_name_a_strict_volume_refuses() {+ for host_name in [":", "a:b", "\\", "a\\b"] {+ assert!(+ !created_and_reachable(host_name),+ "{host_name:?} should be refused at aggregate creation"+ );+ }+}++/// Plain host filenames accepted by strict microVM volumes attach and remain+/// reachable via `FUSE_LOOKUP`.+#[test]+fn file_child_with_a_plain_name_is_created() {+ for host_name in ["file", "a.b", "-x", "\u{e9}t\u{e9}"] {+ assert!(created_and_reachable(host_name), "{host_name:?}");+ }+}
Activity
tangruize commentedon Nov 15, 2026
Suggested Fix
In
open_microvm_volume, validate thatname.as_encoded_bytes()contains neitherb'\\'norb':'(returning ananyhowerror before opening the volume) wheneverfileistrue, so host filenames incompatible with strict microVM alias validation are rejected up front at attachment time rather than failing at guest lookup time.Patch against OpenVMM
9d64daad3cbe14fb0591081b73c6c9648e18d0fb. Save the contents below asfix.patchand rungit apply fix.patch.fix.patch