openvmm: virtiofs: inode deduplication key omits host device number (st_dev)

Abierto
#1,604 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
Medio día
Aptitud para principiantes
64/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Start in vm/devices/virtio/virtiofs/src/inode.rs at the DedupKey::Ino variant and VirtioFsInode::dedup_key, then follow its use into InodeMap::insert in vm/devices/virtio/virtiofs/src/lib.rs. The fix carries device_nr in the stable-ID key, so check every construction and match site of DedupKey::Ino. Done means the two-inode construction in step 5 of the report yields distinct node IDs; run the virtiofs crate tests via cargo nextest to confirm nothing else shifts.

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

Descripción

Summary

On volumes that report stable file IDs, VirtioFs deduplicates inodes in InodeMap by (volume_id, inode_nr) instead of (volume_id, device_nr, inode_nr). When a single shared directory tree spans multiple host st_dev values — such as nested bind mounts or btrfs subvolumes, where every subvolume root has st_ino == 256 on its own anonymous st_dev — two distinct host objects with the same st_ino collide onto one FUSE node ID and overwrite that node's stored host path. Found by testing (also blocks formal verification).

Root Cause

In vm/devices/virtio/virtiofs/src/inode.rs, DedupKey::Ino omits stat.device_nr, and VirtioFsInode::dedup_key keys stable-ID volumes solely by (self.volume_id(), self.inode_nr()):

#[derive(Clone, PartialEq, Eq, Hash)]
pub(crate) enum DedupKey {
    /// `(volume_id, host_inode_number)`, for stable-id volumes.
    Ino(u32, lx::ino_t),
    /// `(volume_id, host_path)`, for volumes that recycle inode numbers.
    Path(u32, PathBuf),
}
    pub(crate) fn dedup_key(&self) -> DedupKey {
        if self.volume.supports_stable_file_id() {
            return DedupKey::Ino(self.volume_id(), self.inode_nr());
        }
        DedupKey::Path(self.volume_id(), self.get_path().clone())
    }

When a lookup resolves a second host object with the same st_ino and file type on a different st_dev, InodeMap::insert takes the Entry::Occupied branch and calls VirtioFsInode::lookup, replacing existing.path with new_path and returning existing's node_id.

Consequence

In POSIX, file identity is (st_dev, st_ino), not st_ino alone. On btrfs, unprivileged users can create subvolumes whose root directory always has st_ino == 256 with a distinct st_dev; container rootfs layers, bind mounts, and nested mounts inside a shared directory produce the same condition on ext4/xfs/overlayfs. If the share root is a btrfs subvolume (FUSE_ROOT_ID == 1, st_ino == 256, path == "") and contains a nested subvolume sub (st_ino == 256, path == "sub"), looking up sub returns nodeid == 1 (producing a directory cycle in the guest VFS) and overwrites the root inode's stored path from "" to "sub", causing subsequent lookups at the share root to resolve inside "sub" and making entries outside "sub" disappear with ENOENT. Colliding regular files across subvolumes or nested mounts likewise alias onto one FUSE node ID, misdirecting path-based operations (getattr, open, setattr, unlink, and microVM subtree policy checks) to whichever path was looked up most recently, and causing microVM save_microvm_state to fail when validate_saved_identity detects that a single inode's recorded aliases have different device_nr values.

Reproduction

  1. On a Linux host with btrfs (for example by running cargo nextest with TMPDIR on a btrfs filesystem), create a btrfs subvolume root, create a nested btrfs subvolume root/sub, and create a regular file root/only_in_root.
  2. Instantiate VirtioFs::new(&root_path, None) so FUSE_ROOT_ID (1) refers to root (st_ino == 256).
  3. Call fs.lookup(&request(FUSE_ROOT_ID), lx::LxStr::from_bytes(b"sub")). It erroneously returns sub.nodeid == FUSE_ROOT_ID (1) and rewrites node 1's path from "" to "sub".
  4. Call fs.lookup(&request(FUSE_ROOT_ID), lx::LxStr::from_bytes(b"only_in_root")). It fails with ENOENT because VirtioFs resolves "sub/only_in_root" instead of "only_in_root".
  5. Without btrfs, constructing two VirtioFsInode values via VirtioFsInode::with_attr with (device_nr: 1, inode_nr: 256) at "a" and (device_nr: 2, inode_nr: 256) at "b" and inserting both into InodeMap reproduces the same node ID collision deterministically on any host filesystem.

Related: #1605, #1619, #1602.

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.