openvmm: virtiofs: microVM readdirplus continues listing when child entry aliases open directory node

Abierto
#1,634 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Start at vm/devices/virtio/virtiofs/src/lib.rs: Fuse::read_dir and read_dir_plus call file.read_dir without request.node_id(). Then read microvm/file.rs::read_dir_microvm and its lookup_helper loop, and trace InodeMap::insert plus VirtioFsInode::lookup in inode.rs for the path overwrite. Reproduce with the issue's dir/sub/after snapshot; done when a child aliasing the open directory is rejected and later names resolve under the original path.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

area: openvmm

Summary

In microVM mode, VirtioFsFile::read_dir_microvm resolves each FUSE_READDIRPLUS entry by calling fs.lookup_helper(&self.inode, name) without checking whether the returned fuse_entry.nodeid equals the FUSE node ID of the open directory being enumerated (request.node_id()). If a child directory entry deduplicates onto self.inode's own node ID, InodeMap::insert rewrites self.inode.path from "dir" to "dir/child" in place, read_dir_microvm emits a self-referential child nodeid to the guest, and subsequent loop iterations resolve remaining snapshot names inside "dir/child" instead of "dir". Found by formal verification.

Root Cause

In vm/devices/virtio/virtiofs/src/lib.rs, Fuse::read_dir and Fuse::read_dir_plus do not pass request.node_id() to file.read_dir, and VirtioFsFile::read_dir_microvm accepts any fuse_entry returned by fs.lookup_helper(&self.inode, name) whose attr.ino matches the snapshot:

    fn read_dir_plus(&self, request: &Request, arg: &fuse_read_in) -> lx::Result<Vec<u8>> {
        if self.is_synthetic_root_handle(request.node_id(), arg.fh) {
            return self.read_synthetic_root_dir(arg.offset, arg.size, true);
        }
        let file = self.get_file(arg.fh)?;
        file.read_dir(self, arg.offset, arg.size, true)
    }
                    let fuse_entry = fs.lookup_helper(&self.inode, name)?;
                    if fuse_entry.attr.ino != entry.guest_inode_id {
                        return Err(lx::Error::EIO);
                    }
                    if !buffer.dir_entry_plus(name, entry.next_cookie, fuse_entry) {
                        return Err(lx::Error::EIO);
                    }

When lookup_helper resolves a child directory whose DedupKey matches self.inode (same file type S_IFDIR), InodeMap::insert takes the Entry::Occupied branch and calls VirtioFsInode::lookup, overwriting *self.inode.path.write() = new_path ("dir/child") and returning fuse_entry.nodeid == request.node_id(). Even the existing fuse_entry.attr.ino != entry.guest_inode_id check does not reject the entry when the snapshot already recorded that inode number.

Consequence

On local Linux filesystems (ext4, xfs, btrfs, tmpfs), an open directory file descriptor keeps its (st_dev, st_ino) allocated on the host until closed, preventing immediate (st_dev, st_ino) reuse by a newly created directory on the same device. However, synthetic, network, or FUSE-backed host shares that reuse or synthesize inode numbers, unlinked/retyped directory cases where the backing filesystem reuses (st_dev, st_ino), or nested subvolumes when DedupKey::Ino omits st_dev (for example a btrfs subvolume directory containing a nested subvolume, both having st_ino == 256) can hit this path. When triggered, read_dir_microvm returns a fuse_direntplus entry whose child nodeid equals its parent directory's nodeid (forming a directory cycle in the guest kernel's dcache) and continues iterating the snapshot while &self.inode now points at "dir/child", resolving later entries from the child directory rather than the open directory.

Reproduction

  1. Create a microVM VirtioFs share containing "dir/sub/after".
  2. Insert a directory VirtioFsInode at path "dir" with dir_node_id whose DedupKey matches "dir/sub" (modeling (dev, ino) reuse or collision), open it as a directory VirtioFsFile, and populate its directory snapshot with [".", "..", "sub", "after"].
  3. Call file.read_dir(&fs, dir_node_id, 0, 4096, true).
  4. Without the guard, lookup_helper on "sub" deduplicates onto dir_node_id, rewrites dir_inode's path from "dir" to "dir/sub", emits "sub" with nodeid == dir_node_id, and then resolves "after" against "dir/sub/after" even though "dir/after" does not exist.

Related: #1611, #1605, #1599.

Lenguaje dominante
Rust
Estrellas
848
Forks
63
Merge medio
13 h 37 min
PR fusionados (30 d)
571

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/nvx

Todos los issues de microsoft/nvx

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.