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

Open Beginner friendly
#1,624 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start in vm/devices/virtio/virtiofs/src/lib.rs at fsync_dir (~L563), then read the sibling handlers read_dir, read_dir_plus and release_dir, which all call is_synthetic_root_handle(request.node_id(), fh) from aggregate.rs (~L216) before touching the handle map. Give fsync_dir the same early return for the synthetic root, ignoring the lookup, and keep the existing get_file/fsync_dir path for real handles. Done looks like the reproduction steps (open_dir on FUSE_ROOT_ID, then fsync_dir with SYNTHETIC_ROOT_FH) returning Ok(()), plus a unit test next to the existing virtiofs tests covering it.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Rust
Stars
848
Forks
63
Avg merge
13h 37m
Merged PRs (30d)
571

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/nvx

All issues in microsoft/nvx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.