openvmm: virtiofs: renaming one hard link onto another hard link of the same file drops the source alias

Aperta
#1,620 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Start in vm/devices/virtio/virtiofs/src/lib.rs at VirtioFs::rename (around lines 532-546) and read how preflight_rename_aliases, remove_alias_prefix and rename_alias_prefix sequence with the host rename; then read the alias bookkeeping in vm/devices/virtio/virtiofs/src/inode.rs (lines 508-542) and the same assumption in vm/devices/virtio/virtiofs/src/microvm/limits.rs preflight_microvm_rename. Reproduce with the FUSE sequence in the issue (lookup f, link a, rename a->f with flags 0, unlink f, getattr) and confirm the node keeps aliases = {"a","f"}. Done means the same-inode rename returns Ok(()) without touching aliases while inode.rename still yields host-side EEXIST/ENOENT/permission errors, plus a regression test covering the follow-up unlink and save_microvm_state path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: openvmm

Summary

Under POSIX rename(2), renaming old_path (a) onto new_path (f) when both are distinct directory entries referring to the same existing file (hard links to the same inode) returns 0 and performs no action on the host filesystem, leaving both a and f intact on disk. VirtioFs::rename, however, unconditionally runs inodes.remove_alias_prefix(inode.volume_id(), &new_path) followed by inodes.rename_alias_prefix(inode.volume_id(), &old_path, &new_path), collapsing {a, f} into {f} and dropping a from the node's tracked aliases even though a still exists on the host. Found by testing.

Root Cause

In VirtioFs::rename, non-exchange renames always assume the host removed new_path and moved old_path onto 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 ("a") and new_path ("f") are distinct hard links to the same host inode and flags has neither RENAME_EXCHANGE nor RENAME_NOREPLACE, the host renameat/renameat2 call returns 0 as a POSIX no-op with both directory entries preserved. Next, VirtioFsInode::remove_alias_prefix and VirtioFsInode::rename_alias_prefix remove "f" from self.aliases and rewrite "a" to "f" (also rewriting self.path to "f"), leaving the VirtioFsInode with aliases = {"f"} and path = "f" while "a" is forgotten. The same assumption appears in InodeMap::preflight_microvm_rename.

Consequence

  • Spurious ENOENT on a still-existing file: If the guest subsequently unlinks "f" (FUSE_UNLINK), remove_alias_prefix removes "f" and leaves aliases empty and self.path stuck at deleted "f", instead of falling back to the surviving hard link "a". Subsequent path-based requests on the held node (get_attr, get_statx, open, set_attr without FATTR_FH, xattr calls, and link) fail with ENOENT even though the file still exists on disk at "a".
  • MicroVM save failure after unlinking "f": Because aliases becomes empty after unlink("f") despite "a" remaining on disk, VirtioFs::save_microvm_state fails with "inode has no bounded reopenable aliases".
  • Incomplete alias set for policy and limit tracking: Dropping "a" from aliases removes "a" from VirtioFsInode::policy_permits_writes multi-link writability checks and undercounts tracked aliases against MAX_ALIASES and MAX_ALIAS_BYTES.

Reproduction

  1. Create a file f in a share root and attach VirtioFs.
  2. Issue FUSE_LOOKUP(FUSE_ROOT_ID, "f") to obtain node.
  3. Issue FUSE_LINK(FUSE_ROOT_ID, "a", node) so both a and f are hard links to the same host inode (node tracks aliases = {"a", "f"}).
  4. Issue FUSE_RENAME(FUSE_ROOT_ID, "a", FUSE_ROOT_ID, "f", 0): the host keeps both a and f on disk with the original inode number, but node drops "a" and keeps only aliases = {"f"}.
  5. Issue FUSE_UNLINK(FUSE_ROOT_ID, "f"): f is removed while a remains intact on disk.
  6. Issue FUSE_GETATTR or FUSE_OPEN on node (which the guest never forgot): it fails with ENOENT because node's primary path still points to "f" and "a" was lost from aliases.

Suggested Fix

For non-exchange renames (flags & RENAME_EXCHANGE == 0), check before updating InodeMap whether old_path == new_path or whether lstat on old_path and new_path before inode.rename succeeds and identifies the same host object ((stat.device_nr, stat.inode_nr) on volumes with stable file IDs). Still invoke inode.rename(name, &new_inode, new_name, flags)? so the host kernel enforces RENAME_NOREPLACE (EEXIST), missing-entry (ENOENT), and type/permission checks, and when the two paths named the same host object, return Ok(()) immediately without running preflight_rename_aliases, remove_alias_prefix, or rename_alias_prefix so all existing aliases remain tracked.

Related: #1610, #1602, #1623.

Lingua principale
Rust
Stelle
848
Fork
63
Merge medio
13h 37m
PR unite (30g)
571

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/nvx

Tutte le issue di microsoft/nvx

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.