openvmm: virtiofs: aggregate synthetic root returns empty EOF reply instead of EINVAL when buffer fits no entry

Aperta Adatta ai principianti
#1,617 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/aggregate.rs presso read_synthetic_root_dir_with (intorno a L314-L366); segui il ciclo che si interrompe su !fit e restituisce Ok(buffer). Confronta con la gestione di EINVAL in VirtioFsFile::read_dir_with (src/file.rs, ~L236-L238) e read_dir_microvm (src/microvm/file.rs, ~L83-L85) per allinearti alla convenzione esistente sugli errori. Fatto significa che un buffer vuoto con voci ancora in sospeso restituisce Err(lx::Error::EINVAL) sia per READDIR sia per READDIRPLUS, con test unitari che usano i passaggi di riproduzione (dimensione 31 / 159 e il caso di continuazione con offset 2).

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

Descrizione

area: openvmm

Summary

When a guest issues FUSE_READDIR or FUSE_READDIRPLUS on an aggregate mount's synthetic root directory with a non-zero buffer size too small to hold the next directory entry, VirtioFs::read_synthetic_root_dir_with returns Ok(Vec::new()) instead of Err(lx::Error::EINVAL). Because FUSE defines an empty directory read reply as end-of-directory, the guest truncates the synthetic root's directory listing instead of receiving EINVAL. Found by testing.

Root Cause

In vm/devices/virtio/virtiofs/src/aggregate.rs#L314-L366, VirtioFs::read_synthetic_root_dir_with breaks out of the entry-serialization loop as soon as write_synthetic_dot or write_child_entry reports !fit, and unconditionally returns Ok(buffer) even when buffer is still empty:

            if !fit {
                break;
            }
            index = next;
        }
        Ok(buffer)

For example, a plain FUSE_READDIR entry for . requires fuse_dirent_align(size_of::<fuse_dirent>() + 1) = 32 bytes (fuse_direntplus requires 160 bytes), so any size in 1..=31 (1..=159 for FUSE_READDIRPLUS), or any continuation read whose size cannot hold the aligned entry of the next child share name, causes !fit on the first attempted entry and returns a 0-byte buffer. By contrast, real share directories reject undersized buffers that have remaining entries but fit none with EINVAL in both VirtioFsFile::read_dir_with and VirtioFsFile::read_dir_microvm.

Consequence

FUSE and getdents64 treat a 0-byte FUSE_READDIR / FUSE_READDIRPLUS reply as end-of-directory rather than a short-buffer error. A caller supplying a small buffer at offset 0 sees an empty root directory, and a caller whose continuation buffer fits . and .. (64 bytes) or short share names before hitting a longer share name receives a silent early EOF that hides the remaining shares instead of failing with EINVAL as Linux getdents64 and regular share directories do.

Reproduction

  1. Construct an aggregate VirtioFs via VirtioFs::new_microvm_aggregate with at least one child share (for example "work").
  2. Open the synthetic root directory via Fuse::open_dir(&fs, &request(FUSE_ROOT_ID), lx::O_RDONLY as u32).
  3. Call Fuse::read_dir at offset = 0 with size = 31 (or Fuse::read_dir_plus with size = 159), or first read . and .. with size = 64 (next_cookie = 2) and then call Fuse::read_dir at offset = 2 with size = 31.
  4. Observe Ok(vec![]) instead of Err(lx::Error::EINVAL).

Related: #1598, #1632, #1624.

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.