Skip to content

openvmm: fuse: ReplySender::send_error panics on i32::MIN overflow in debug builds #1625

Open

Description

@tangruize

Summary

fuse::ReplySender::send_error negates its error: i32 argument with -error when populating fuse_out_header.error. Because -i32::MIN cannot be represented as an i32, passing i32::MIN triggers a signed negation overflow panic in builds with overflow checks enabled. Found by formal verification.

Root Cause

In vm/devices/support/fs/fuse/src/reply.rs#L37-L45, ReplySender::send_error accepts any i32 error code and negates it directly with -error on reply.rs#L42:

    /// Send an error reply.
    fn send_error(&mut self, unique: u64, error: i32) -> io::Result<()> {
        if error != 0 {
            tracing::debug!(unique, error, "reply");
        }

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

lx::Error wraps an arbitrary i32 via lx::Error::from_lx, and Session::dispatch forwards e.value() directly to sender.send_error(unique, e.value()) in vm/devices/support/fs/fuse/src/session.rs#L90-L98 without restricting the range of i32 values.

Consequence

If ReplySender::send_error is called with i32::MIN—either directly or through Session::dispatch when a Fuse implementation returns Err(lx::Error::from_lx(i32::MIN))—builds with integer overflow checks enabled (such as dev builds, where panic = 'abort' is configured) panic with attempt to negate with overflow and abort the process. Release builds without overflow checks already wrap -i32::MIN to i32::MIN. This path is not reachable in practice through VirtioFs, whose errors originate from positive lx errno constants and host OS error codes mapped by lxutil.

Reproduction

Call sender.send_error(1, i32::MIN) on any ReplySender, or initialize a fuse::Session around a Fuse implementation whose get_attr returns Err(lx::Error::from_lx(i32::MIN)) and dispatch a FUSE_GETATTR request.

The regression tests reply::tests::send_error_takes_any_code and session::tests::dispatch_replies_any_error_code in fix.patch exercise both paths via cargo nextest run --profile agent -p fuse. Before the fix, both tests fail with a panic (attempt to negate with overflow at vm/devices/support/fs/fuse/src/reply.rs:42:45); after the fix, both pass and emit an error reply header with error = i32::MIN (i32::MIN.wrapping_neg()).

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

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Replace -error with error.wrapping_neg() in ReplySender::send_error so that every i32 value is handled without panicking when overflow checks are enabled, matching existing release-build behavior. Add unit tests covering ReplySender::send_error and Session::dispatch across boundary i32 values including i32::MIN.

    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..8fcb8a1c4 100644
    --- a/vm/devices/support/fs/fuse/src/reply.rs
    +++ b/vm/devices/support/fs/fuse/src/reply.rs
    @@ -39,7 +39,7 @@ fn send_error(&mut self, unique: u64, error: i32) -> io::Result<()> {
                 tracing::debug!(unique, error, "reply");
             }
     
    -        let header = make_header(unique, 0, -error);
    +        let header = make_header(unique, 0, error.wrapping_neg());
             let header = header.as_bytes();
             self.send(&[io::IoSlice::new(header)])
         }
    @@ -202,3 +202,34 @@ 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(())
    +        }
    +    }
    +
    +    /// An error reply is sent for any error code, `i32::MIN` included.
    +    #[test]
    +    fn send_error_takes_any_code() {
    +        let mut sender = CapturingSender::default();
    +        for error in [i32::MIN, i32::MIN + 1, -1, 1, lx::EIO, i32::MAX] {
    +            sender.send_error(1, error).unwrap();
    +            let header = fuse_out_header::read_from_prefix(&sender.data).unwrap().0;
    +            assert_eq!(header.error, error.wrapping_neg(), "error {error}");
    +            assert_eq!(header.len as usize, sender.data.len());
    +        }
    +    }
    +}
    diff --git a/vm/devices/support/fs/fuse/src/session.rs b/vm/devices/support/fs/fuse/src/session.rs
    index 4508e7944..825e971ad 100644
    --- a/vm/devices/support/fs/fuse/src/session.rs
    +++ b/vm/devices/support/fs/fuse/src/session.rs
    @@ -1203,6 +1203,32 @@ fn init_max_pages_uses_ceiling_division() {
             );
         }
     
    +    /// A file system whose `get_attr` fails with the error code `i32::MIN`.
    +    struct MinErrorFs;
    +
    +    impl Fuse for MinErrorFs {
    +        fn get_attr(&self, _request: &Request, _flags: u32, _fh: u64) -> lx::Result<fuse_attr_out> {
    +            Err(lx::Error::from_lx(i32::MIN))
    +        }
    +    }
    +
    +    /// The session replies to a failed operation whatever its error code.
    +    #[test]
    +    fn dispatch_replies_any_error_code() {
    +        let session = Session::new(MinErrorFs);
    +        let mut sender = CapturingSender::default();
    +        session.dispatch(Request::new(FUSE_INIT_REQUEST).unwrap(), &mut sender, None);
    +        assert!(session.is_initialized());
    +        session.dispatch(
    +            Request::new(FUSE_GETATTR_REQUEST).unwrap(),
    +            &mut sender,
    +            None,
    +        );
    +        let reply_header = fuse_out_header::read_from_prefix(&sender.data).unwrap().0;
    +        assert_eq!(reply_header.error, i32::MIN);
    +        assert_eq!(reply_header.len as usize, sender.data.len());
    +    }
    +
         /// 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