openvmm: virtiofs: zero-length virtqueue payload descriptors truncate FUSE request reads and reply writes
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/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/virtio_util.rs at VirtioPayloadReader::next_payload/get_payload and the mirror in VirtioPayloadWriter; read Read::read, RequestReader::read_until, and Write::write to see how a zero-length VirtioQueuePayload yields remaining == 0. Then follow the callers in vm/devices/virtio/virtiofs/src/virtio.rs: process_virtiofs_request and VirtioReplySender::send. Done means scatter-gather chains containing zero-length readable/writable descriptors no longer cause premature EOF, EINVAL, or WriteZero, verified with tests for the split FUSE_INIT and FUSE_LOOKUP chains.
Written by the indexing model from the issue text.
Description
Summary
VirtioPayloadReader::get_payload and VirtioPayloadWriter::get_payload advance past an exhausted buffer with a single if self.offset == payload.length as usize check rather than a while loop (and next_payload does not skip zero-length descriptors). Whenever a descriptor chain contains a zero-length readable or writable VirtioQueuePayload after a non-empty buffer (or two consecutive zero-length buffers at the start of the chain), get_payload returns a buffer with remaining == 0, causing Read::read to report premature EOF (Ok(0)), RequestReader::read_until to fail with EINVAL, and Write::write to return Ok(0) so VirtioReplySender::send aborts with WriteZero and completes the virtqueue item with 0 bytes written. Found by testing.
Root Cause
In VirtioPayloadReader, next_payload selects the next !p.writeable descriptor regardless of p.length, and get_payload advances at most once when self.offset == payload.length as usize:
fn next_payload(&mut self) {
self.current = self.payload.find(|p| !p.writeable);
}
fn get_payload(&mut self) -> Option<&'payload VirtioQueuePayload> {
let payload = self.current?;
if self.offset == payload.length as usize {
self.next_payload();
self.offset = 0;
}
self.current
}
VirtioPayloadWriter has the identical single-step logic for writable descriptors:
fn next_payload(&mut self) {
self.current = self.payload.find(|p| p.writeable);
}
fn get_payload(&mut self) -> Option<&'payload VirtioQueuePayload> {
let payload = self.current?;
if self.offset == payload.length as usize {
self.next_payload();
self.offset = 0;
}
self.current
}
When next_payload() lands on a descriptor with length == 0 (either after finishing a preceding non-empty descriptor where self.offset == payload.length, or after advancing past a first leading length == 0 descriptor onto a second length == 0 descriptor), get_payload() returns Some(payload) with payload.length == 0 and self.offset == 0 even when subsequent descriptors in the chain still hold readable data or writable reply capacity.
Consequence
Valid scatter-gather virtqueue chains that include zero-length descriptors fail across all three payload I/O paths:
- Header and fixed-struct reads (
Read::read->read_exact): InRead::read,remainingevaluates to0, soreadreturnsOk(0)for a non-empty caller buffer, whichread_exacttreats asErrorKind::UnexpectedEof. If the 40-bytefuse_in_headerspans[readable(30), readable(0), readable(74)](or starts with[readable(0), readable(0), readable(104)]),fuse::Request::newfails inprocess_virtiofs_request, firing(worker.notify_corruption)()and completing the descriptor with0used bytes and no FUSE reply. - NUL-terminated string reads (
RequestReader::read_until): Inread_until,get_current_remaining_len()returns0upon advancing onto the empty descriptor and immediately returnsErr(lx::Error::EINVAL)without inspecting following readable descriptors (for example,FUSE_LOOKUPsplit as[readable(40), readable(0), readable(10)]). - Reply writes (
Write::write->write_allinVirtioReplySender::send): InWrite::write,remainingevaluates to0andwritereturnsOk(0).VirtioReplySender::sendcallswriter.write_all(buf)?, which fails withErrorKind::WriteZerobefore updatingself.bytes_written. On aFUSE_INITchain[readable(104), writable(16), writable(0), writable(64)], the 16-bytefuse_out_headeris written intowritable(16), the 64-bytefuse_init_outbody fails atwritable(0), and the queue item completes withbytes_written == 0even though FUSE state transitions (and partial guest-memory header writes) already took place.
Reproduction
- Construct guest memory containing a valid 104-byte
FUSE_INITrequest (40-bytefuse_in_header+64-bytefuse_init_in) and 80 bytes of writable reply space. - Submit the request through
process_virtiofs_requestwith readable descriptors split as[readable(30), readable(0), readable(74), writable(80)]:VirtioPayloadReaderreads 30 bytes, advances ontoreadable(0), returnsOk(0)on the remaining 10 header bytes, triggersnotify_corruption, and returns0bytes written. - Submit a
FUSE_LOOKUPrequest split as[readable(40), readable(0), readable(6), writable(144)]where"hello\0"resides in the third descriptor:read_until(0)seesget_current_remaining_len() == 0atreadable(0)and replies with-EINVAL. - Submit
FUSE_INITwith writable descriptors split as[readable(104), writable(16), writable(0), writable(64)]:VirtioReplySender::sendwrites the 16-bytefuse_out_header, hitsWriteZeroonwritable(0)when writingfuse_init_out, and returnsbytes_written == 0.
Suggested Fix
Skip zero-length descriptors in both VirtioPayloadReader and VirtioPayloadWriter by changing next_payload to filter on p.length > 0 (self.payload.find(|p| !p.writeable && p.length > 0) and self.payload.find(|p| p.writeable && p.length > 0)) and/or changing if self.offset == payload.length as usize in both get_payload implementations to while let Some(payload) = self.current { if self.offset < payload.length as usize { break; } self.next_payload(); self.offset = 0; }.
- 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
-
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
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
pact-foundation/pact-plugins#125 ·
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jolars/panache#627 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
facebookexperimental/hermit#347 ·
Maintainers usually reply within 1 day