Repository navigation
Description
Summary
In microVM mode, VirtioFsFile::read_dir_microvm resolves each FUSE_READDIRPLUS entry by calling fs.lookup_helper(&self.inode, name) without checking whether the returned fuse_entry.nodeid equals the FUSE node ID of the open directory being enumerated (request.node_id()). If a child directory entry deduplicates onto self.inode's own node ID, InodeMap::insert rewrites self.inode.path from "dir" to "dir/child" in place, read_dir_microvm emits a self-referential child nodeid to the guest, and subsequent loop iterations resolve remaining snapshot names inside "dir/child" instead of "dir". Found by formal verification.
Root Cause
In vm/devices/virtio/virtiofs/src/lib.rs, Fuse::read_dir and Fuse::read_dir_plus do not pass request.node_id() to file.read_dir, and VirtioFsFile::read_dir_microvm accepts any fuse_entry returned by fs.lookup_helper(&self.inode, name) whose attr.ino matches the snapshot:
fn read_dir_plus(&self, request: &Request, arg: &fuse_read_in) -> lx::Result<Vec<u8>> {
if self.is_synthetic_root_handle(request.node_id(), arg.fh) {
return self.read_synthetic_root_dir(arg.offset, arg.size, true);
}
let file = self.get_file(arg.fh)?;
file.read_dir(self, arg.offset, arg.size, true)
} let fuse_entry = fs.lookup_helper(&self.inode, name)?;
if fuse_entry.attr.ino != entry.guest_inode_id {
return Err(lx::Error::EIO);
}
if !buffer.dir_entry_plus(name, entry.next_cookie, fuse_entry) {
return Err(lx::Error::EIO);
}When lookup_helper resolves a child directory whose DedupKey matches self.inode (same file type S_IFDIR), InodeMap::insert takes the Entry::Occupied branch and calls VirtioFsInode::lookup, overwriting *self.inode.path.write() = new_path ("dir/child") and returning fuse_entry.nodeid == request.node_id(). Even the existing fuse_entry.attr.ino != entry.guest_inode_id check does not reject the entry when the snapshot already recorded that inode number.
Consequence
On local Linux filesystems (ext4, xfs, btrfs, tmpfs), an open directory file descriptor keeps its (st_dev, st_ino) allocated on the host until closed, preventing immediate (st_dev, st_ino) reuse by a newly created directory on the same device. However, synthetic, network, or FUSE-backed host shares that reuse or synthesize inode numbers, unlinked/retyped directory cases where the backing filesystem reuses (st_dev, st_ino), or nested subvolumes when DedupKey::Ino omits st_dev (for example a btrfs subvolume directory containing a nested subvolume, both having st_ino == 256) can hit this path. When triggered, read_dir_microvm returns a fuse_direntplus entry whose child nodeid equals its parent directory's nodeid (forming a directory cycle in the guest kernel's dcache) and continues iterating the snapshot while &self.inode now points at "dir/child", resolving later entries from the child directory rather than the open directory.
Reproduction
- Create a microVM
VirtioFsshare containing"dir/sub/after". - Insert a directory
VirtioFsInodeat path"dir"withdir_node_idwhoseDedupKeymatches"dir/sub"(modeling(dev, ino)reuse or collision), open it as a directoryVirtioFsFile, and populate its directory snapshot with[".", "..", "sub", "after"]. - Call
file.read_dir(&fs, dir_node_id, 0, 4096, true). - Without the guard,
lookup_helperon"sub"deduplicates ontodir_node_id, rewritesdir_inode's path from"dir"to"dir/sub", emits"sub"withnodeid == dir_node_id, and then resolves"after"against"dir/sub/after"even though"dir/after"does not exist.
Activity
tangruize commentedon Nov 15, 2026
Suggested Fix
Thread
dir_node_id: u64(request.node_id()) throughVirtioFsFile::read_dirintoVirtioFsFile::read_dir_microvm. Immediately afterfs.lookup_helper(&self.inode, name)succeeds inread_dir_microvm, checkif fuse_entry.nodeid == dir_node_id: release the newly acquired lookup reference (fs.forget(fuse_entry.nodeid, 1)), and stop enumeration immediately — returningOk(buffer)if earlier entries were already buffered (so the guest can release their lookup references) orErr(lx::Error::EIO)ifbuffer.is_empty(). When merging alongside the siblingread_dir_microvmfixes that roll back lookup references viafs.forget_lookups/stoppedon mid-listing failures and drop thefuse_entry.attr.ino != entry.guest_inode_idcheck for btrfs subvolumes, combine the post-lookup guard intoif node_id == dir_node_id || !buffer.dir_entry_plus(name, entry.next_cookie, fuse_entry)before callingfs.forget_lookups(node_id, 1)and settingstopped = Some(lx::Error::EIO).Patch against OpenVMM
9d64daad3cbe14fb0591081b73c6c9648e18d0fb. Save the contents below asfix.patchand rungit apply fix.patch.fix.patch