openvmm: virtiofs: FUSE_FSYNCDIR on aggregate synthetic root handle fails with EBADF
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
- Domain
- operating-systems
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
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
- Construct an aggregate
VirtioFsviaVirtioFs::new_microvm_aggregate(orVirtioFs::new_aggregate). - Call
Fuse::open_dir(&fs, &request(FUSE_ROOT_ID), lx::O_RDONLY as u32)to obtainfh(SYNTHETIC_ROOT_FH). - Call
Fuse::fsync_dir(&fs, &request(FUSE_ROOT_ID), fh, 0). - Observe
Err(lx::Error::EBADF)instead ofOk(()).
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/nvx
-
area: ci
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area: ci
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesOpenarea: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/nvx#1632 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/nvx#1628 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
microsoft/nvx#1629 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
obi1kenobi/cargo-semver-checks#1814 ·
Maintainers usually reply within 1 day
-
community differential help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
hffgzktbcc-blip/ounce-core#489 · 1 comment ·
Maintainers usually reply within 1 day
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pbakaus/impeccable#1560 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
pact-foundation/pact-plugins#125 ·