Repository navigation
Description
Summary
In microVM virtio-fs, InodeMap::preflight_microvm_insert checks self.inodes_by_key.get(&inode.dedup_key()) without verifying that the existing entry has the same file_type() as inode. When a host inode number (DedupKey) is reused by an object of a different file type (such as a file unlinked while still tracked by the guest and replaced by a directory or symlink that reuses the freed host inode number), InodeMap::dedup_entry evicts the old inodes_by_key entry and allocates a brand-new node ID in inodes_by_node_id, yet preflight_microvm_insert ran preflight_microvm_alias_add instead of preflight_microvm_new_inode, bypassing the MAX_INODES (4096) cap and can_insert() check. Found during formal specification (blocks formal verification).
Root Cause
InodeMap::preflight_microvm_insert assumes any match in self.inodes_by_key will reuse the existing node and add an alias:
pub(crate) fn preflight_microvm_insert(&self, inode: &VirtioFsInode) -> lx::Result<()> {
let path = inode.clone_path();
Self::validate_microvm_alias_path(&path)?;
if let Some((existing, _)) = self.inodes_by_key.get(&inode.dedup_key()) {
return self.preflight_microvm_alias_add(existing, &path);
}
self.preflight_microvm_new_inode(&path)
}However, InodeMap::insert and InodeMap::insert_reserved look up inodes_by_key through InodeMap::dedup_entry, which explicitly evicts the inodes_by_key mapping whenever existing.file_type() != inode.file_type() while leaving existing live inside self.inodes_by_node_id.values:
fn dedup_entry<'a>(
inodes_by_key: &'a mut HashMap<DedupKey, (Arc<VirtioFsInode>, u64)>,
inode: &VirtioFsInode,
) -> Entry<'a, DedupKey, (Arc<VirtioFsInode>, u64)> {
let key = inode.dedup_key();
if inodes_by_key
.get(&key)
.is_some_and(|(existing, _)| existing.file_type() != inode.file_type())
{
inodes_by_key.remove(&key);
}
inodes_by_key.entry(key)
}Because dedup_entry returns Entry::Vacant, InodeMap::insert allocates a fresh node in self.inodes_by_node_id without ever having checked self.inodes_by_node_id.values.len() >= MAX_INODES || !self.inodes_by_node_id.can_insert().
Consequence
When self.inodes_by_node_id.values.len() has reached MAX_INODES (4096), looking up or inserting a host object whose (volume_id, device_nr, inode_nr) matches a still-tracked inode of a different file type bypasses MAX_INODES and inserts a 4,097th (and arbitrarily more) active inode into inodes_by_node_id.values. Once inodes_by_node_id.values.len() > MAX_INODES, subsequent microVM snapshot capture fails in save_microvm_state (anyhow::ensure!(inodes.inodes_by_node_id.values.len() <= MAX_INODES)). In addition, if inodes_by_node_id is exhausted (!can_insert()), InodeMap::insert reaches dedup_entry first and evicts existing from inodes_by_key before inodes_by_node_id.insert fails with ENOSPC; conversely, if existing already holds MAX_ALIASES_PER_INODE (256) aliases while inodes_by_node_id still has room, preflight_microvm_insert falsely rejects the retyped object with ENOSPC even though no alias is added to existing.
Reproduction
- Attach a writable microVM share, look up a regular file
"file"so its(volume_id, device_nr, inode_nr)is recorded ininodes_by_keyandinodes_by_node_id, and populateinodes_by_node_idup toMAX_INODES(4096). - Replace that host inode number with an object of another file type (for example, unlink
"file"while keeping its FUSE node referenced, create a directory or symlink that reuses the freed host inode number on tmpfs/ext4, or construct aVirtioFsInodesharingstat.device_nrandstat.inode_nrwithS_IFDIRmode). - Call
inodes.insert_microvm(other)(viaFUSE_LOOKUPorFUSE_READDIRPLUS):insert_microvmsucceeds instead of returningErr(lx::Error::ENOSPC), growinginodes_by_node_id.values.len()to4097(MAX_INODES + 1), after whichsave_microvm_statefails.
Activity
tangruize commentedon Nov 15, 2026
Suggested Fix
In
InodeMap::preflight_microvm_insert(vm/devices/virtio/virtiofs/src/microvm/limits.rs), guard theinodes_by_keyfast path withexisting.file_type() == inode.file_type()so any dedup-key match whose file type differs falls through toself.preflight_microvm_new_inode(&path), matchingInodeMap::dedup_entry.Patch against OpenVMM
9d64daad3cbe14fb0591081b73c6c9648e18d0fb. Save the contents below asfix.patchand rungit apply fix.patch.fix.patch