openvmm: virtiofs: inode lookup count wraps to zero at u64::MAX

Aperta
#1,633 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
68/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/inode.rs around lines 236-262: compare lookup/inc_lookup (which use fetch_add) with the neighbouring forget, which already uses AtomicU64::update with saturating_sub. Decide whether the restore path in vm/devices/virtio/virtiofs/src/microvm/state.rs (validate_microvm_state) should also reject an implausible lookup_count, then add a unit test that replays the reproduction steps and asserts the inode survives fs.forget(node_id, 1) followed by get_attr. Done means a lookup at u64::MAX keeps the count saturated and the node stays in InodeMap; run the virtiofs crate tests with cargo test -p virtiofs.

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

Descrizione

area: openvmm

Summary

VirtioFsInode::lookup and VirtioFsInode::inc_lookup increment lookup_count with AtomicU64::fetch_add(1, Ordering::AcqRel), which uses wrapping arithmetic at u64::MAX. When an inode's lookup_count is u64::MAX — reachable directly via microVM saved-state restore without 2^64 live requests — one additional FUSE_LOOKUP, FUSE_READDIRPLUS, or FUSE_LINK wraps lookup_count to 0, allowing the next FUSE_FORGET to evict the still-referenced inode from InodeMap. Found by formal verification.

Root Cause

In vm/devices/virtio/virtiofs/src/inode.rs, both VirtioFsInode::lookup and VirtioFsInode::inc_lookup use fetch_add(1, Ordering::AcqRel) rather than saturating addition, even though VirtioFsInode::forget immediately below already uses AtomicU64::update with saturating_sub:

    /// Increments the lookup count.
    pub fn lookup(&self, new_path: PathBuf) {
        self.lookup_count.fetch_add(1, Ordering::AcqRel);
        self.aliases.write().insert(new_path.clone());
        let mut path = self.path.write();
        *path = new_path;
    }

    /// Increments the lookup count without updating the path.
    ///
    /// This is used when returning an existing inode in a FUSE reply (e.g., for hard links)
    /// where the kernel will track the reference and later send a forget.
    pub fn inc_lookup(&self) {
        self.lookup_count.fetch_add(1, Ordering::AcqRel);
    }

In microVM mode, validate_microvm_state accepts any SavedInode with inode.lookup_count != 0, including u64::MAX, and restores it verbatim into VirtioFsInode::lookup_count.

Consequence

Once lookup_count wraps from u64::MAX to 0, the inode remains in InodeMap with a zero reference count until any FUSE_FORGET(node_id, n) arrives. At that point, Fuse::forget computes 0u64.saturating_sub(n) == 0 and removes the node from InodeMap while the guest still holds active FUSE references to node_id. Subsequent guest operations on node_id fail with EINVAL (request for unknown inode), and in microVM mode save_microvm_state also fails if an open handle still points to the evicted inode (open handle refers to an untracked inode).

Reproduction

  1. Create a temporary directory containing a file "f", instantiate VirtioFs::new(dir.path(), None), and look up "f" once to obtain node_id.
  2. Set that inode's lookup_count to u64::MAX (simulating a restored SavedInode with lookup_count: u64::MAX or cumulative lookups).
  3. Look up "f" a second time (or call inode.inc_lookup()). lookup_count wraps from u64::MAX to 0.
  4. Call fs.forget(node_id, 1) and then fs.get_attr on node_id. forget evicts node_id from InodeMap, and get_attr fails with lx::Error::EINVAL.

Related: #1627.

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.