Skip to content

openvmm: fuse: FUSE_IOCTL reply sends request input data instead of filesystem output #1615

Open

Description

@tangruize

Summary

In fuse::Session::dispatch_helper, the FuseOperation::Ioctl arm calls self.fs.ioctl(&request, arg, data)? and validates the returned output buffer out.1 against arg.out_size, but then passes the request's input buffer data instead of &out.1 to sender.send_arg_data(...). As a result, successful FUSE_IOCTL replies echo the request's input bytes rather than returning the filesystem's ioctl output. Found by static code inspection and unit testing.

Root Cause

In vm/devices/support/fs/fuse/src/session.rs#L336-L353, Session::dispatch_helper unpacks FuseOperation::Ioctl { arg, data }, receives out: (i32, Vec<u8>) from self.fs.ioctl(...), checks out.1.len() > arg.out_size as usize, and then mistakenly passes data on session.rs#L351:

            FuseOperation::Ioctl { arg, data } => {
                let out = self.fs.ioctl(&request, arg, data)?;
                if out.1.len() > arg.out_size as usize {
                    return Err(lx::Error::EINVAL.into());
                }

                // As far as I can tell, the fields other than result are only used for CUSE.
                sender.send_arg_data(
                    request.unique(),
                    fuse_ioctl_out {
                        result: out.0,
                        flags: 0,
                        in_iovs: 0,
                        out_iovs: 0,
                    },
                    data,
                )?;
            }

Consequence

Any fuse::Fuse implementation whose ioctl callback succeeds receives wrong reply data on the wire: the fuse_ioctl_out.result field carries out.0, but the trailing payload bytes carry the request's input data (arg.in_size bytes) instead of the filesystem's output out.1 (and can even exceed arg.out_size when arg.in_size > arg.out_size). Current built-in filesystems in virtiofs (VirtioFs, DormantMicrovmFs, and SectionFs) do not override Fuse::ioctl, which defaults to Err(lx::Error::ENOSYS), so they return ENOSYS before reaching send_arg_data. Note that ReplySender::send_arg_data also has a separate defect where fuse_out_header.len omits the trailing data length, tracked in the related issue below.

Reproduction

Implement fuse::Fuse with an ioctl method returning Ok((42, vec![9, 9, 9, 9])), initialize a Session, and dispatch a FUSE_IOCTL request with in_size = 8, out_size = 4, and input payload [1, 2, 3, 4, 5, 6, 7, 8].

The regression test session::tests::dispatch_ioctl_replies_with_file_system_output in fix.patch runs this scenario via cargo nextest run --profile agent -p fuse. Before the fix, the test fails because the reply payload bytes following fuse_ioctl_out are [1, 2, 3, 4, 5, 6, 7, 8] instead of [9, 9, 9, 9]; after the fix, the test passes and the reply payload carries [9, 9, 9, 9].

Related: #1616.

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Pass &out.1 instead of data as the data slice argument to sender.send_arg_data in the FuseOperation::Ioctl arm of Session::dispatch_helper. Because out.1.len() <= arg.out_size as usize is already checked immediately beforehand, the reply payload will carry the filesystem's output bounded by arg.out_size.

    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/session.rs b/vm/devices/support/fs/fuse/src/session.rs
    index 4508e7944..a95a75955 100644
    --- a/vm/devices/support/fs/fuse/src/session.rs
    +++ b/vm/devices/support/fs/fuse/src/session.rs
    @@ -348,7 +348,7 @@ fn dispatch_helper(
                             in_iovs: 0,
                             out_iovs: 0,
                         },
    -                    data,
    +                    &out.1,
                     )?;
                 }
                 FuseOperation::Poll { arg: _ } => {
    @@ -1203,6 +1203,62 @@ fn init_max_pages_uses_ceiling_division() {
             );
         }
     
    +    /// A file system whose `ioctl` returns output of its own.
    +    struct IoctlFs;
    +
    +    impl Fuse for IoctlFs {
    +        fn ioctl(
    +            &self,
    +            _request: &Request,
    +            _arg: &fuse_ioctl_in,
    +            _data: &[u8],
    +        ) -> lx::Result<(i32, Vec<u8>)> {
    +            Ok((42, vec![9, 9, 9, 9]))
    +        }
    +    }
    +
    +    /// The reply to `FUSE_IOCTL` carries the file system's output, not the
    +    /// request's input.
    +    #[test]
    +    fn dispatch_ioctl_replies_with_file_system_output() {
    +        let session = Session::new(IoctlFs);
    +        let mut sender = CapturingSender::default();
    +        session.dispatch(Request::new(FUSE_INIT_REQUEST).unwrap(), &mut sender, None);
    +        assert!(session.is_initialized());
    +
    +        // 8 bytes of input, room for 4 bytes of output.
    +        let arg = fuse_ioctl_in {
    +            fh: 7,
    +            flags: 0,
    +            cmd: 0x539,
    +            arg: 0,
    +            in_size: 8,
    +            out_size: 4,
    +        };
    +        let header = fuse_in_header {
    +            len: (size_of::<fuse_in_header>() + size_of::<fuse_ioctl_in>() + 8) as u32,
    +            opcode: FUSE_IOCTL,
    +            unique: 2,
    +            nodeid: 1,
    +            uid: 0,
    +            gid: 0,
    +            pid: 0,
    +            padding: 0,
    +        };
    +        let mut data = Vec::new();
    +        data.extend_from_slice(header.as_bytes());
    +        data.extend_from_slice(arg.as_bytes());
    +        data.extend_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]);
    +        session.dispatch(Request::new(data.as_slice()).unwrap(), &mut sender, None);
    +
    +        let reply_header = fuse_out_header::read_from_prefix(&sender.data).unwrap().0;
    +        assert_eq!(reply_header.error, 0);
    +        let rest = &sender.data[size_of::<fuse_out_header>()..];
    +        let out = fuse_ioctl_out::read_from_prefix(rest).unwrap().0;
    +        assert_eq!(out.result, 42);
    +        assert_eq!(&rest[size_of::<fuse_ioctl_out>()..], &[9, 9, 9, 9]);
    +    }
    +
         /// Creates a FUSE_LOOKUP request with a name that's too long (256 bytes, exceeds NAME_MAX of 255)
         fn make_lookup_name_too_long() -> Vec<u8> {
             let mut data = vec![0u8; 297]; // 40 byte header + 256 byte name + 1 null terminator
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