Skip to content

openvmm: fuse: FUSE_INIT with header len smaller than fuse_in_header underflows payload length #1607

Open

Description

@tangruize

Summary

fuse::Request::read_operation subtracts size_of::<fuse_in_header>() (40 bytes) from header.len as usize without checking that header.len is at least the header size when parsing FUSE_INIT. A guest-supplied FUSE_INIT message with header.len < 40 triggers an unsigned subtraction underflow, panicking in builds with overflow checks enabled and wrapping payload_len in release builds. Found by testing (also blocks formal verification).

Root Cause

In vm/devices/support/fs/fuse/src/request.rs#L133-L160, Request::read_operation only checks whether header.len exceeds the total bytes available in the message (reader.remaining_len() + size_of_val(header)), and never checks the lower bound header.len as usize >= size_of::<fuse_in_header>() before computing payload_len at request.rs#L150:

    fn read_operation(header: &fuse_in_header, mut reader: impl RequestReader) -> FuseOperation {
        if header.len as usize > reader.remaining_len() + size_of_val(header) {
            tracelimit::error_ratelimited!(
                opcode = header.opcode,
                unique = header.unique,
                header_len = header.len,
                len = reader.remaining_len() + size_of_val(header),
                "Invalid message length",
            );
            return FuseOperation::Invalid;
        }

        // ...
        if header.opcode == FUSE_INIT {
            let payload_len = (header.len as usize) - size_of::<fuse_in_header>();
            let available = payload_len.min(size_of::<fuse_init_in>());
            if available < FUSE_COMPAT_INIT_IN_SIZE as usize {
                // ...
                return FuseOperation::Invalid;
            }

When reader.read_type::<fuse_in_header>() succeeds in Request::new, at least 40 bytes were present in the input buffer, so any header.len in 0..40 passes the upper-bound check on line 134 and underflows (header.len as usize) - 40 on line 150.

Consequence

Every virtio-fs request from the guest is parsed by fuse::Request::new in vm/devices/virtio/virtiofs/src/virtio.rs#L482. Any guest with a virtio-fs device can send a 40-byte fuse_in_header with opcode = FUSE_INIT and len < 40 (for example 0, 8, or 39). In builds with integer overflow checks enabled (such as dev builds, where panic = 'abort' is configured), this panics with attempt to subtract with overflow and aborts the VMM or device process. In release builds without overflow checks, payload_len wraps to usize::MAX - 39..=usize::MAX, clamping available to size_of::<fuse_init_in>() (64 bytes) and attempting to read a 64-byte fuse_init_in payload from trailing descriptor bytes despite the invalid header.len.

Reproduction

Construct a FUSE request buffer containing a fuse_in_header with opcode = FUSE_INIT and len set to 0, 8, or 39 (size_of::<fuse_in_header>() as u32 - 1), optionally followed by 16 payload bytes, and call fuse::Request::new(data.as_slice()).

The regression test request::tests::parse_init_len_below_header_size_is_invalid in fix.patch exercises len values 0, 8, and 39 with cargo nextest run --profile agent -p fuse. Before the fix, the test fails with a panic (attempt to subtract with overflow at vm/devices/support/fs/fuse/src/request.rs:150:31); after the fix, it passes and each malformed request decodes to FuseOperation::Invalid (for which Session replies EIO).

Related: #1596, #1597.

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Replace the unchecked subtraction in Request::read_operation with (header.len as usize).saturating_sub(size_of::<fuse_in_header>()). When header.len is smaller than size_of::<fuse_in_header>(), payload_len and available evaluate to 0, which is less than FUSE_COMPAT_INIT_IN_SIZE (16) and is cleanly rejected by the existing minimum-payload check as FuseOperation::Invalid. Valid FUSE_INIT messages (header.len >= 56) are unaffected.

    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/request.rs b/vm/devices/support/fs/fuse/src/request.rs
    index 99132cefd..f18240e07 100644
    --- a/vm/devices/support/fs/fuse/src/request.rs
    +++ b/vm/devices/support/fs/fuse/src/request.rs
    @@ -147,7 +147,7 @@ fn read_operation(header: &fuse_in_header, mut reader: impl RequestReader) -> Fu
             // FUSE_INIT_EXT is supported). Read whatever is available and
             // zero-fill the rest so that flags2 defaults to 0 for old kernels.
             if header.opcode == FUSE_INIT {
    -            let payload_len = (header.len as usize) - size_of::<fuse_in_header>();
    +            let payload_len = (header.len as usize).saturating_sub(size_of::<fuse_in_header>());
                 let available = payload_len.min(size_of::<fuse_init_in>());
                 if available < FUSE_COMPAT_INIT_IN_SIZE as usize {
                     tracelimit::error_ratelimited!(
    @@ -306,6 +306,32 @@ fn parse_init_too_small_payload_is_invalid() {
             assert!(matches!(request.operation, FuseOperation::Invalid));
         }
     
    +    #[test]
    +    fn parse_init_len_below_header_size_is_invalid() {
    +        // A FUSE_INIT whose header `len` field is smaller than `fuse_in_header`
    +        // must decode to `Invalid` rather than underflowing payload length.
    +        for len in [0, 8, size_of::<fuse_in_header>() as u32 - 1] {
    +            let header = fuse_in_header {
    +                len,
    +                opcode: FUSE_INIT,
    +                unique: 1,
    +                nodeid: 0,
    +                uid: 0,
    +                gid: 0,
    +                pid: 0,
    +                padding: 0,
    +            };
    +            let mut data = Vec::new();
    +            data.extend_from_slice(header.as_bytes());
    +            data.extend_from_slice(&[7, 0, 0, 0, 27, 0, 0, 0, 0, 0, 2, 0, 251, 255, 63, 0]);
    +            let request = Request::new(data.as_slice()).unwrap();
    +            assert!(
    +                matches!(request.operation, FuseOperation::Invalid),
    +                "len {len}"
    +            );
    +        }
    +    }
    +
         #[test]
         fn parse_init_extended_preserves_flags2() {
             // Build a full 64-byte extended FUSE_INIT payload with FUSE_INIT_EXT
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