openvmm: virtiofs: renaming a path onto itself drops all tracked aliases at or below that path

Open
#1,610 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start at VirtioFs::rename in vm/devices/virtio/virtiofs/src/lib.rs (~lines 532-546); the non-exchange branch calls remove_alias_prefix then rename_alias_prefix, so short-circuit when old_path == new_path. Read remove_alias_prefix/rename_alias_prefix in inode.rs and the same simulation in microvm/limits.rs preflight_microvm_rename. Done means a self-rename leaves aliases() untouched and save_microvm_state in microvm/fs.rs no longer fails; add a regression test in the virtiofs crate.

Written by the indexing model from the issue text.

Description

Summary

When a guest renames a directory entry onto the exact same directory and name (old_path == new_path without RENAME_EXCHANGE), the host rename succeeds as a POSIX no-op, but VirtioFs::rename still executes inodes.remove_alias_prefix(inode.volume_id(), &new_path) followed by inodes.rename_alias_prefix(inode.volume_id(), &old_path, &new_path). Because new_path == old_path, remove_alias_prefix deletes every tracked alias at or below old_path before rename_alias_prefix runs, leaving live inodes with empty or incomplete aliases sets even though nothing changed on the host filesystem. Found during formal specification (blocks formal verification).

Root Cause

In VirtioFs::rename, non-exchange renames assume old_path and new_path are distinct and unconditionally purge new_path from the alias table before rewriting old_path to new_path:

let old_path = inode.child_path(name)?;
let new_path = new_inode.child_path(new_name)?;
self.check_writable_entry(&inode, &old_path)?;
self.check_writable_entry(&new_inode, &new_path)?;
let exchange = flags & RENAME_EXCHANGE != 0;
self.preflight_rename_aliases(inode.volume_id(), &old_path, &new_path, exchange)?;
inode.rename(name, &new_inode, new_name, flags)?;
let mut inodes = self.inner.inodes.write();
if exchange {
    inodes.exchange_alias_prefixes(inode.volume_id(), &old_path, &new_path);
} else {
    inodes.remove_alias_prefix(inode.volume_id(), &new_path);
    inodes.rename_alias_prefix(inode.volume_id(), &old_path, &new_path);
}

When old_path == new_path (request.node_id() == new_dir and name == new_name, or two nodes aliasing the same directory with identical child names), the host renameat/renameat2 call with flags == 0 succeeds without modifying the directory entry. Next, VirtioFsInode::remove_alias_prefix removes every alias with prefix new_path (== old_path) from every live inode in that volume, leaving VirtioFsInode::rename_alias_prefix with no matching aliases left to rewrite. The same destructive simulation also runs in InodeMap::preflight_microvm_rename.

Consequence

  • MicroVM save/restore failure: VirtioFs::save_microvm_state requires !aliases.is_empty() for every live inode, so renaming any looked-up file or non-empty directory onto itself causes subsequent microVM state saves to fail with "inode has no bounded reopenable aliases".
  • Spurious ENOENT on multi-link files: If an inode has two hard links out/a and out/b, renaming out/a onto out/a drops "out/a" from aliases and switches path to "out/b"; subsequently unlinking out/b leaves path stuck at deleted "out/b" and causes path-based operations (get_attr, open) on the held node to fail with ENOENT even though out/a still exists on disk.
  • Broken path deduplication and alias accounting: On volumes using DedupKey::Path, InodeMap::rebuild_dedup_keys skips inodes with inode.aliases().is_empty(), causing subsequent lookups to allocate duplicate node IDs for the same live file or directory, while microVM alias-count and byte-budget limits (MAX_ALIASES, MAX_ALIAS_BYTES) no longer account for the dropped paths.

Reproduction

  1. Configure a microVM virtio-fs share with writable_paths = ["out"] containing out/existing.
  2. FUSE_LOOKUP "out" (out_node) and "out/existing" (file_node); file_node initially has aliases = {"out/existing"}.
  3. Issue FUSE_RENAME (or FUSE_RENAME2 with flags = 0) from (out_node, "existing") to (out_node, "existing").
  4. The rename returns Ok(()) and out/existing remains intact on the host, but fs.get_inode(file_node).unwrap().aliases() is now empty ({}), and calling save_microvm_state fails with "inode has no bounded reopenable aliases".

Related: #1620, #1602, #1601.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/nvx

All issues in microsoft/nvx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.