openvmm: virtiofs: microVM readdirplus continues listing when child entry aliases open directory node
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- operating-systems
Research direction
Start at vm/devices/virtio/virtiofs/src/lib.rs: Fuse::read_dir and read_dir_plus call file.read_dir without request.node_id(). Then read microvm/file.rs::read_dir_microvm and its lookup_helper loop, and trace InodeMap::insert plus VirtioFsInode::lookup in inode.rs for the path overwrite. Reproduce with the issue's dir/sub/after snapshot; done when a child aliasing the open directory is rejected and later names resolve under the original path.
Written by the indexing model from the issue text.
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.
Related: #1611, #1605, #1599.
- 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