openvmm: virtiofs: FUSE_FSYNCDIR on aggregate synthetic root handle fails with EBADF

Aperta Adatta ai principianti
#1,624 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Inizia in vm/devices/virtio/virtiofs/src/lib.rs a fsync_dir (~L563), poi leggi gli handler fratelli read_dir, read_dir_plus e release_dir, che chiamano tutti is_synthetic_root_handle(request.node_id(), fh) da aggregate.rs (~L216) prima di toccare la mappa degli handle. Dai a fsync_dir lo stesso ritorno anticipato per la root sintetica, ignorando il lookup, e mantieni il percorso esistente get_file/fsync_dir per gli handle reali. Fatto assomiglia ai passaggi di riproduzione (open_dir su FUSE_ROOT_ID, poi fsync_dir con SYNTHETIC_ROOT_FH) che restituiscono Ok(()), più un unit test accanto ai test virtiofs esistenti che lo copre.

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

Descrizione

area: openvmm

Summary

On an aggregate virtiofs mount (microVM or direct aggregate), FUSE_OPENDIR on FUSE_ROOT_ID (1) returns the sentinel handle SYNTHETIC_ROOT_FH (u64::MAX) without inserting an entry into self.inner.files. While get_attr, get_statx, read_dir, read_dir_plus, and release_dir all recognize SYNTHETIC_ROOT_FH, VirtioFs::fsync_dir ignores request and looks up fh directly in self.get_file(fh), causing FUSE_FSYNCDIR (fsync() / fdatasync() on an open directory descriptor for the aggregate mount point) to fail with EBADF. Found by testing.

Root Cause

In vm/devices/virtio/virtiofs/src/lib.rs#L471-L503 (as well as get_attr and get_statx), open_dir hands out SYNTHETIC_ROOT_FH for the synthetic aggregate root, and directory handlers check self.is_synthetic_root_handle(request.node_id(), fh) before consulting the file-handle map. However, VirtioFs::fsync_dir omits that check and unconditionally calls self.get_file(fh):

    fn fsync_dir(&self, _request: &Request, fh: u64, flags: u32) -> lx::Result<()> {
        let file = self.get_file(fh)?;
        let data_only = flags & FUSE_FSYNC_FDATASYNC != 0;
        file.fsync_dir(data_only)
    }

Because SYNTHETIC_ROOT_FH is never inserted into self.inner.files, self.get_file(fh) logs "Request for unknown file" and returns Err(lx::Error::EBADF).

Consequence

When guest software opens an aggregate mount-point directory (open("/mnt", O_RDONLY | O_DIRECTORY)) and invokes fsync(fd) or fdatasync(fd) (as archive extractors, package managers, backup tools, and atomic file-replacement helpers routinely do on parent/mount directories), the Linux FUSE client sends FUSE_FSYNCDIR with the handle returned by FUSE_OPENDIR and receives EBADF despite holding a valid open directory descriptor.

Reproduction

  1. Construct an aggregate VirtioFs via VirtioFs::new_microvm_aggregate (or VirtioFs::new_aggregate).
  2. Call Fuse::open_dir(&fs, &request(FUSE_ROOT_ID), lx::O_RDONLY as u32) to obtain fh (SYNTHETIC_ROOT_FH).
  3. Call Fuse::fsync_dir(&fs, &request(FUSE_ROOT_ID), fh, 0).
  4. Observe Err(lx::Error::EBADF) instead of Ok(()).

Related: #1627, #1617, #1632, #1599.

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.