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

Open
#1,625 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
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start at vm/devices/support/fs/fuse/src/reply.rs around line 42, in ReplySender::send_error, where make_header(unique, 0, -error) is built; read vm/devices/support/fs/fuse/src/session.rs around Session::dispatch to see how lx::Error::value() reaches it. Run cargo nextest run --profile agent -p fuse and use the named tests reply::tests::send_error_takes_any_code and session::tests::dispatch_replies_any_error_code as the finish line for an i32::MIN reply. The body references a fix.patch, so confirm whether that patch is already proposed before duplicating it.

Written by the indexing model from the issue text.

Description

area: openvmm

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.

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.