Skip to content

openvmm: fuse: data reply exceeding requested size panics in Session::send_max_size #1629

Open

Description

@tangruize

Summary

fuse::Session::send_max_size enforces with assert!(data.len() <= max_size as usize) that a filesystem's data reply does not exceed the guest-requested byte count. Because both dev and release profiles configure panic = 'abort', any fuse::Fuse implementation that returns more bytes than requested in read, read_dir, read_dir_plus, get_xattr, or list_xattr aborts the entire VMM process instead of failing the FUSE request with an error reply. Found by formal verification.

Root Cause

In vm/devices/support/fs/fuse/src/session.rs, Session::send_max_size uses an unconditional assert! to validate the length of the Vec<u8> returned by the Fuse trait implementation against the guest's max_size: u32:

    /// Send a reply, validating it doesn't exceed the requested size.
    ///
    /// If it exceeds the maximum size, this causes a panic because that's a bug in the file system.
    fn send_max_size(
        sender: &mut impl ReplySender,
        unique: u64,
        data: &[u8],
        max_size: u32,
    ) -> Result<(), OperationError> {
        assert!(data.len() <= max_size as usize);
        sender.send_data(unique, data)?;
        Ok(())
    }

Session::dispatch_helper calls Self::send_max_size for Read (L204-L207), GetXAttr (L245-L247), ListXAttr (L260-L262), ReadDir (L280-L283), and ReadDirPlus (L373-L376). Meanwhile, the corresponding public Fuse trait methods return lx::Result<Vec<u8>> without documenting or enforcing an upper bound in the return type, whereas FuseOperation::Ioctl in the same dispatcher (L334-L336) already rejects an oversized buffer gracefully with Err(lx::Error::EINVAL.into()).

Consequence

OpenVMM sets panic = 'abort' in both [profile.dev] and [profile.release] (Cargo.toml). If a custom or future fuse::Fuse backend passed to fuse::Session::new or virtiofs::VirtioFsDevice::new returns a payload even one byte larger than arg.size, the session dispatcher aborts the entire VMM process rather than failing the offending FUSE request. OpenVMM's built-in VirtioFs backend sizes its read, xattr, and directory buffers from the guest's size parameter and does not trigger this panic, making this a fuse::Session API hardening issue.

Reproduction

Implement fuse::Fuse with read returning Ok(vec![0; arg.size as usize + 1]), initialize a fuse::Session with FUSE_INIT, and dispatch a FUSE_READ request with size = 4096. On commit 9d64daad3cbe14fb0591081b73c6c9648e18d0fb, dispatching the request panics at vm/devices/support/fs/fuse/src/session.rs:576:9 with assertion failed: data.len() <= max_size as usize. Running cargo nextest run --profile agent -p fuse -E 'test(dispatch_read_reply_larger_than_size_fails)' with the regression test in fix.patch reproduces the panic prior to the fix and passes with a -EIO reply afterward.

Related: #1628, #1631, #1630, #1625.

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Replace assert!(data.len() <= max_size as usize) in Session::send_max_size with an explicit check if data.len() > max_size as usize that logs a rate-limited error via tracelimit::error_ratelimited! (recording len and max_size) and returns Err(lx::Error::EIO.into()) so Session::dispatch replies to the guest with -EIO instead of aborting.

    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..6b158f62f 100644
    --- a/vm/devices/support/fs/fuse/src/session.rs
    +++ b/vm/devices/support/fs/fuse/src/session.rs
    @@ -566,14 +566,21 @@ fn send_release_if_interrupted<
     
         /// Send a reply, validating it doesn't exceed the requested size.
         ///
    -    /// If it exceeds the maximum size, this causes a panic because that's a bug in the file system.
    +    /// If it exceeds the maximum size, that's a bug in the file system, and the request fails.
         fn send_max_size(
             sender: &mut impl ReplySender,
             unique: u64,
             data: &[u8],
             max_size: u32,
         ) -> Result<(), OperationError> {
    -        assert!(data.len() <= max_size as usize);
    +        if data.len() > max_size as usize {
    +            tracelimit::error_ratelimited!(
    +                len = data.len(),
    +                max_size,
    +                "Reply exceeds the requested size"
    +            );
    +            return Err(lx::Error::EIO.into());
    +        }
             sender.send_data(unique, data)?;
             Ok(())
         }
    @@ -1259,4 +1266,62 @@ fn make_lookup_name_too_long() -> Vec<u8> {
     
             data
         }
    +
    +    /// Builds a request with the given opcode, node and payload.
    +    fn make_request(opcode: u32, nodeid: u64, payload: &[u8]) -> Vec<u8> {
    +        let header = fuse_in_header {
    +            len: (size_of::<fuse_in_header>() + payload.len()) as u32,
    +            opcode,
    +            unique: 2,
    +            nodeid,
    +            uid: 0,
    +            gid: 0,
    +            pid: 0,
    +            padding: 0,
    +        };
    +        let mut data = Vec::new();
    +        data.extend_from_slice(header.as_bytes());
    +        data.extend_from_slice(payload);
    +        data
    +    }
    +
    +    /// A file system whose `read` returns one byte more than requested.
    +    struct OversizedReadFs;
    +
    +    impl Fuse for OversizedReadFs {
    +        fn read(&self, _request: &Request, arg: &fuse_read_in) -> lx::Result<Vec<u8>> {
    +            Ok(vec![0; arg.size as usize + 1])
    +        }
    +    }
    +
    +    /// An initialized session of `fs`, and the sender that saw its replies.
    +    fn initialized<T: 'static + Fuse + Send + Sync>(fs: T) -> (Session, CapturingSender) {
    +        let session = Session::new(fs);
    +        let mut sender = CapturingSender::default();
    +        session.dispatch(Request::new(FUSE_INIT_REQUEST).unwrap(), &mut sender, None);
    +        assert!(session.is_initialized());
    +        (session, sender)
    +    }
    +
    +    /// The error of the last reply `sender` saw.
    +    fn reply_error(sender: &CapturingSender) -> i32 {
    +        fuse_out_header::read_from_prefix(&sender.data)
    +            .unwrap()
    +            .0
    +            .error
    +    }
    +
    +    /// A reply larger than the guest asked for fails the request with `EIO`.
    +    #[test]
    +    fn dispatch_read_reply_larger_than_size_fails() {
    +        let (session, mut sender) = initialized(OversizedReadFs);
    +        let mut arg = fuse_read_in::new_zeroed();
    +        arg.size = 4096;
    +        session.dispatch(
    +            Request::new(make_request(FUSE_READ, 2, arg.as_bytes()).as_slice()).unwrap(),
    +            &mut sender,
    +            None,
    +        );
    +        assert_eq!(reply_error(&sender), -lx::EIO);
    +    }
     }
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