openvmm: virtiofs: renaming one hard link onto another hard link of the same file drops the source alias
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
- Ambito
- operating-systems
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
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
ENOENTon a still-existing file: If the guest subsequently unlinks"f"(FUSE_UNLINK),remove_alias_prefixremoves"f"and leavesaliasesempty andself.pathstuck 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_attrwithoutFATTR_FH, xattr calls, andlink) fail withENOENTeven though the file still exists on disk at"a". - MicroVM save failure after unlinking
"f": Becausealiasesbecomes empty afterunlink("f")despite"a"remaining on disk,VirtioFs::save_microvm_statefails with"inode has no bounded reopenable aliases". - Incomplete alias set for policy and limit tracking: Dropping
"a"fromaliasesremoves"a"fromVirtioFsInode::policy_permits_writesmulti-link writability checks and undercounts tracked aliases againstMAX_ALIASESandMAX_ALIAS_BYTES.
Reproduction
- Create a file
fin a share root and attachVirtioFs. - Issue
FUSE_LOOKUP(FUSE_ROOT_ID, "f")to obtainnode. - Issue
FUSE_LINK(FUSE_ROOT_ID, "a", node)so bothaandfare hard links to the same host inode (nodetracksaliases = {"a", "f"}). - Issue
FUSE_RENAME(FUSE_ROOT_ID, "a", FUSE_ROOT_ID, "f", 0): the host keeps bothaandfon disk with the original inode number, butnodedrops"a"and keeps onlyaliases = {"f"}. - Issue
FUSE_UNLINK(FUSE_ROOT_ID, "f"):fis removed whilearemains intact on disk. - Issue
FUSE_GETATTRorFUSE_OPENonnode(which the guest never forgot): it fails withENOENTbecausenode's primarypathstill points to"f"and"a"was lost fromaliases.
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/nvx
-
area: ci
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
area: ci
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesApertaarea: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/nvx#1632 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
microsoft/nvx#1628 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: openvmm
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
microsoft/nvx#1629 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di microsoft/nvx
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
obi1kenobi/cargo-semver-checks#1814 ·
I maintainer di solito rispondono entro 1 giorno
-
community differential help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
hffgzktbcc-blip/ounce-core#489 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add support for TODO for AIApertaneeds triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pbakaus/impeccable#1560 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
pact-foundation/pact-plugins#125 ·