openvmm: fuse: reply exceeding u32 header length panics in make_header

Open Beginner friendly
#1,628 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start in vm/devices/support/fs/fuse/src/reply.rs, reading make_header and each ReplySender helper that calls it. Reproduce with cargo nextest run --profile agent -p fuse -E 'test(reply_longer_than_u32_is_refused) | test(dispatch_reply_longer_than_u32_is_not_sent)'. Trace callers such as session.rs send_max_size and lib.rs read_link; done means oversized replies surface as io::Error instead of panicking and both tests pass.

Written by the indexing model from the issue text.

Description

area: openvmm

Summary

fuse::reply::make_header computes the total FUSE reply length (size_of::<fuse_out_header>() + extra_len) and converts it to u32 using .try_into().unwrap(), while ReplySender::send_string computes value.len() + 1 without saturation. Whenever a fuse::Fuse implementation or ReplySender caller sends more than u32::MAX - 16 payload bytes (such as a FUSE_READ reply of u32::MAX bytes or a u32::MAX - 16-byte symlink target), make_header panics and aborts the VMM process instead of returning an io::Error. Found by formal verification.

Root Cause

In vm/devices/support/fs/fuse/src/reply.rs, every ReplySender helper (send_arg, send_error, send_data, send_arg_data, and send_string) constructs the 16-byte fuse_out_header via an infallible make_header helper that unwraps try_into() into u32:

    /// Send a string reply.
    fn send_string(&mut self, unique: u64, value: lx::LxString) -> io::Result<()> {
        tracing::trace!(unique, len = value.len(), "reply");
        let header = make_header(unique, value.len() + 1, 0);
        let header = header.as_bytes();
        self.send(&[
            io::IoSlice::new(header),
            io::IoSlice::new(value.as_bytes()),
            io::IoSlice::new(&[0]),
        ])
    }
}

fn make_header(unique: u64, extra_len: usize, error: i32) -> fuse_out_header {
    fuse_out_header {
        len: (size_of::<fuse_out_header>() + extra_len)
            .try_into()
            .unwrap(),
        error,
        unique,
    }
}

Even when a Fuse implementation strictly honors the guest's u32 size parameter in read, read_dir, read_dir_plus, get_xattr, or list_xattr (passing Session::send_max_size for max_size in (u32::MAX - 15)..=u32::MAX), adding size_of::<fuse_out_header>() (16 bytes) pushes the total frame size past u32::MAX, causing .try_into().unwrap() to panic. Likewise, Fuse::read_link returns an arbitrary LxString without any length cap, and send_string adds 1 for the NUL terminator unchecked before calling make_header.

Consequence

Because OpenVMM sets panic = 'abort' in both [profile.dev] and [profile.release] (Cargo.toml), a Fuse implementation returning a valid-within-arg.size buffer of u32::MAX - 15 to u32::MAX bytes (or a symlink target of at least u32::MAX - 16 bytes) aborts the entire VMM process rather than surfacing an io::Error from ReplySender. OpenVMM's built-in VirtioFs implementation bounds replies to at most 1 MiB (MAX_GUEST_BUFFER_SIZE), so this is not reachable through VirtioFs in practice.

Reproduction

Call ReplySender::send_data with u32::MAX as usize - 15 zero bytes, call ReplySender::send_string with a u32::MAX as usize - 16-byte LxString, or dispatch a FUSE_READ request with arg.size = u32::MAX to a Fuse implementation whose read returns Ok(vec![0; arg.size as usize]). On commit 9d64daad3cbe14fb0591081b73c6c9648e18d0fb, all three panic at vm/devices/support/fs/fuse/src/reply.rs:91:14 with called Result::unwrap() on an Err value: TryFromIntError(PosOverflow). Running cargo nextest run --profile agent -p fuse -E 'test(reply_longer_than_u32_is_refused) | test(dispatch_reply_longer_than_u32_is_not_sent)' reproduces both panics before fix.patch and passes afterward.

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

Dominant language
Rust
Stars
848
Forks
63
Avg merge
13h 37m
Merged PRs (30d)
571

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/nvx

All issues in microsoft/nvx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.