Skip to content

openvmm: fuse: ReplySender::send_arg_data omits trailing data length from fuse_out_header.len #1616

Open

Description

@tangruize

Summary

fuse::ReplySender::send_arg_data sends three slices (fuse_out_header, the serialized arg struct, and data), but computes fuse_out_header.len using only size_of_val(&arg) and omits data.len(). Any reply sent via send_arg_data with a non-empty data buffer therefore carries a fuse_out_header.len field smaller than the actual message written to the client. Found by static code inspection and unit testing.

Root Cause

In vm/devices/support/fs/fuse/src/reply.rs#L56-L72, ReplySender::send_arg_data constructs the reply header via make_header on reply.rs#L64 with extra_len = size_of_val(&arg), omitting data.len() even though IoSlice::new(data) is transmitted on line 70:

    fn send_arg_data<T: std::fmt::Debug + IntoBytes + Immutable + KnownLayout>(
        &mut self,
        unique: u64,
        arg: T,
        data: &[u8],
    ) -> io::Result<()> {
        tracing::trace!(unique, ?arg, len = data.len(), "reply");

        let header = make_header(unique, size_of_val(&arg), 0);
        let header = header.as_bytes();
        let arg = arg.as_bytes();
        self.send(&[
            io::IoSlice::new(header),
            io::IoSlice::new(arg),
            io::IoSlice::new(data),
        ])
    }

By contrast, send_arg, send_data, and send_string in the same trait include their full payload sizes in make_header.

Consequence

When send_arg_data sends a non-empty data buffer, the FUSE client receives a reply whose fuse_out_header.len understates the wire message length by data.len() bytes (for example, len = 32 for a 36-byte FUSE_IOCTL reply consisting of a 16-byte fuse_out_header, a 16-byte fuse_ioctl_out, and 4 bytes of data), causing the client to truncate or reject the reply. Within fuse::Session, only the FuseOperation::Ioctl arm in vm/devices/support/fs/fuse/src/session.rs#L343-L352 invokes send_arg_data, and current built-in filesystems in virtiofs (VirtioFs, DormantMicrovmFs, and SectionFs) leave Fuse::ioctl at its default ENOSYS implementation, so only Fuse implementations with a custom ioctl returning output data (or direct callers of ReplySender::send_arg_data) hit this mismatch.

Reproduction

Call ReplySender::send_arg_data(1, fuse_ioctl_out { result: 42, flags: 0, in_iovs: 0, out_iovs: 0 }, &[9, 9, 9, 9]) on a capturing ReplySender implementation and compare the len field of the resulting fuse_out_header with the total length of the sent buffer.

The regression test reply::tests::reply_header_len_is_reply_len in fix.patch checks all six ReplySender helpers via cargo nextest run --profile agent -p fuse. Before the fix, send_empty, send_error, send_arg, send_data, and send_string pass, while send_arg_data fails with left: 32 vs right: 36; after the fix, all assertions pass.

Related: #1615, #1628.

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Update ReplySender::send_arg_data to call make_header(unique, size_of_val(&arg) + data.len(), 0) so that fuse_out_header.len includes the header, the serialized argument struct, and the trailing data slice. Add unit tests verifying that every ReplySender helper sets fuse_out_header.len equal to the total number of bytes sent.

    Patch against OpenVMM 9d64daad3cbe14fb0591081b73c6c9648e18d0fb. Save the contents below as fix.patch and run git apply fix.patch.

    fix.patch
    diff --git a/vm/devices/support/fs/fuse/src/reply.rs b/vm/devices/support/fs/fuse/src/reply.rs
    index d765af056..0f199543b 100644
    --- a/vm/devices/support/fs/fuse/src/reply.rs
    +++ b/vm/devices/support/fs/fuse/src/reply.rs
    @@ -61,7 +61,7 @@ fn send_arg_data<T: std::fmt::Debug + IntoBytes + Immutable + KnownLayout>(
         ) -> io::Result<()> {
             tracing::trace!(unique, ?arg, len = data.len(), "reply");
     
    -        let header = make_header(unique, size_of_val(&arg), 0);
    +        let header = make_header(unique, size_of_val(&arg) + data.len(), 0);
             let header = header.as_bytes();
             let arg = arg.as_bytes();
             self.send(&[
    @@ -202,3 +202,57 @@ fn write_padding(writer: &mut impl Write, count: usize) {
         const PADDING: [u8; 8] = [0; 8];
         writer.write_all(&PADDING[..count]).unwrap();
     }
    +
    +#[cfg(test)]
    +mod tests {
    +    use super::*;
    +    use zerocopy::FromBytes;
    +
    +    /// Keeps the bytes of the last reply.
    +    #[derive(Default)]
    +    struct CapturingSender {
    +        data: Vec<u8>,
    +    }
    +
    +    impl ReplySender for CapturingSender {
    +        fn send(&mut self, bufs: &[io::IoSlice<'_>]) -> io::Result<()> {
    +            self.data = bufs.iter().flat_map(|s| s.iter()).copied().collect();
    +            Ok(())
    +        }
    +    }
    +
    +    impl CapturingSender {
    +        /// The `len` field of the last reply's header.
    +        fn header_len(&self) -> usize {
    +            fuse_out_header::read_from_prefix(&self.data).unwrap().0.len as usize
    +        }
    +    }
    +
    +    /// Every reply's header gives the length of the whole reply: the header,
    +    /// the argument, and any trailing data.
    +    #[test]
    +    fn reply_header_len_is_reply_len() {
    +        let mut sender = CapturingSender::default();
    +        let arg = || fuse_ioctl_out {
    +            result: 42,
    +            flags: 0,
    +            in_iovs: 0,
    +            out_iovs: 0,
    +        };
    +
    +        sender.send_empty(1).unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +        sender.send_error(1, lx::Error::ENOENT.value()).unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +        sender.send_arg(1, arg()).unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +        sender.send_data(1, &[1, 2, 3]).unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +        sender
    +            .send_string(1, lx::LxString::from_vec(b"target".to_vec()))
    +            .unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +        sender.send_arg_data(1, arg(), &[9, 9, 9, 9]).unwrap();
    +        assert_eq!(sender.header_len(), sender.data.len());
    +    }
    +}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: openvmmInitial title-keyword triage suggestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions