Skip to content

openvmm: fuse: dispatch_init asserts on unoffered Fuse::init flags and trusts mutable SessionInfo capabilities #1630

Open

Description

@tangruize

Summary

fuse::Session::dispatch_init checks negotiated feature flags after calling Fuse::init(&mut SessionInfo) using assert!(info.want & !info.capable == 0) and assert!(info.want2 & !info.capable2 == 0), and reads info.capable / info.capable2 back out of the mutable SessionInfo reference even though SessionInfo implements From<SessionInfoState>. A Fuse::init implementation that requests flags the guest did not offer panics and aborts the VMM process instead of failing FUSE_INIT with -EIO, while one that replaces *info via SessionInfoState can forge capable / capable2 and bypass the check altogether. Found by formal verification.

Root Cause

In vm/devices/support/fs/fuse/src/session.rs, dispatch_init passes &mut SessionInfo to self.fs.init(&mut info) and then asserts against info.capable and info.capable2:

        info.max_write = DEFAULT_MAX_PAGES * PAGE_SIZE;
        self.fs.init(&mut info);

        assert!(info.want & !info.capable == 0);
        // If the filesystem cleared FUSE_INIT_EXT from want, force want2 to
        // zero so we never reply with flags2 the kernel won't expect.
        if info.want & FUSE_INIT_EXT == 0 {
            info.want2 = 0;
        }
        assert!(info.want2 & !info.capable2 == 0);

Fuse::init exposes info.want and info.want2 as pub u32 fields without documenting that setting bits outside info.capable() / info.capable2() will panic, and dispatch_init aborts rather than rejecting the negotiation with lx::Error::EIO. In addition, although SessionInfo's major, minor, capable, and capable2 fields are private, SessionInfoState is publicly re-exported at vm/devices/support/fs/fuse/src/lib.rs with pub fields and impl From<SessionInfoState> for SessionInfo:

impl From<SessionInfoState> for SessionInfo {
    fn from(state: SessionInfoState) -> Self {
        Self {
            major: state.major,
            minor: state.minor,
            max_readahead: state.max_readahead,
            capable: state.capable,
            capable2: state.capable2,
            want: state.want,
            want2: state.want2,
            max_background: state.max_background,
            congestion_threshold: state.congestion_threshold,
            max_write: state.max_write,
            time_gran: state.time_gran,
        }
    }
}

Because dispatch_init compares info.want and info.want2 against info.capable and info.capable2 after self.fs.init(&mut info) returns, an external Fuse::init implementation can assign *info = SessionInfo::from(SessionInfoState { capable: !0, capable2: !0, .. }) to bypass capability validation and alter the saved protocol state.

Consequence

With panic = 'abort' enabled in both [profile.dev] and [profile.release] (Cargo.toml), any Fuse implementation that sets an unadvertised want or want2 bit during FUSE_INIT crashes the VMM process instead of returning -EIO and keeping the session uninitialized. Conversely, replacing *info through SessionInfo::from(SessionInfoState { .. }) allows init to emit unoffered fuse_init_out flags to the guest and corrupt Session::save_state(). OpenVMM's built-in VirtioFs::init masks want against info.capable() and does not construct SessionInfoState, so this is not triggered through VirtioFs today.

Reproduction

Dispatch FUSE_INIT on a fuse::Session whose Fuse::init sets info.want |= 1 << 30 when the request flags omit bit 30; on commit 9d64daad3cbe14fb0591081b73c6c9648e18d0fb, this panics at vm/devices/support/fs/fuse/src/session.rs:502:9 (assertion failed: info.want & !info.capable == 0). Dispatching FUSE_INIT against a Fuse::init that assigns *info = SessionInfo::from(SessionInfoState { capable: !0, capable2: !0, want: 1 << 30, .. }) succeeds with error == 0 instead of -EIO. Running cargo nextest run --profile agent -p fuse -E 'test(dispatch_init_unoffered_flags_fails) | test(dispatch_init_forged_capable_via_session_info_state_fails)' reproduces both failures before fix.patch and passes afterward.

Related: #1629, #1628, #1631.

Activity

  1. tangruize commented on Nov 15, 2026

    @tangruize
    ContributorAuthor

    Suggested Fix

    Save (major, minor, capable, capable2) from info into local bindings before calling self.fs.init(&mut info), validate info.want & !capable == 0 and (after zeroing info.want2 when info.want & FUSE_INIT_EXT == 0) info.want2 & !capable2 == 0 against the saved capability bitmasks, and on failure log a rate-limited error via tracelimit::error_ratelimited!, reset *info = SessionInfo::default() so Session::save_state() remains valid for an uninitialized session, and return Err(lx::Error::EIO.into()). On success, restore info.major, info.minor, info.capable, and info.capable2 from the saved pre-init bindings before building fuse_init_out.

    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..2abfd6bed 100644
    --- a/vm/devices/support/fs/fuse/src/session.rs
    +++ b/vm/devices/support/fs/fuse/src/session.rs
    @@ -497,15 +497,37 @@ fn dispatch_init(
             }
             info.time_gran = 1;
             info.max_write = DEFAULT_MAX_PAGES * PAGE_SIZE;
    +        let (major, minor, capable, capable2) =
    +            (info.major, info.minor, info.capable, info.capable2);
             self.fs.init(&mut info);
     
    -        assert!(info.want & !info.capable == 0);
    +        if info.want & !capable != 0 {
    +            tracelimit::error_ratelimited!(
    +                want = info.want,
    +                capable,
    +                "File system wanted FUSE flags the client did not offer",
    +            );
    +            *info = SessionInfo::default();
    +            return Err(lx::Error::EIO.into());
    +        }
             // If the filesystem cleared FUSE_INIT_EXT from want, force want2 to
             // zero so we never reply with flags2 the kernel won't expect.
             if info.want & FUSE_INIT_EXT == 0 {
                 info.want2 = 0;
             }
    -        assert!(info.want2 & !info.capable2 == 0);
    +        if info.want2 & !capable2 != 0 {
    +            tracelimit::error_ratelimited!(
    +                want2 = info.want2,
    +                capable2,
    +                "File system wanted extended FUSE flags the client did not offer",
    +            );
    +            *info = SessionInfo::default();
    +            return Err(lx::Error::EIO.into());
    +        }
    +        info.major = major;
    +        info.minor = minor;
    +        info.capable = capable;
    +        info.capable2 = capable2;
     
             // Report the negotiated values back to the client.
             // TODO: Set map_alignment for DAX.
    @@ -1259,4 +1281,95 @@ fn make_lookup_name_too_long() -> Vec<u8> {
     
             data
         }
    +
    +    /// The error code in the last reply sent to `sender`.
    +    fn reply_error(sender: &CapturingSender) -> i32 {
    +        fuse_out_header::read_from_prefix(&sender.data)
    +            .unwrap()
    +            .0
    +            .error
    +    }
    +
    +    /// A file system whose `init` demands flags the client did not offer.
    +    struct GreedyInitFs {
    +        extra_want: u32,
    +        extra_want2: u32,
    +    }
    +
    +    impl Fuse for GreedyInitFs {
    +        fn init(&self, info: &mut SessionInfo) {
    +            info.want |= self.extra_want;
    +            info.want2 |= self.extra_want2;
    +        }
    +    }
    +
    +    /// `init` setting `want` or `want2` bits not in `capable` / `capable2`
    +    /// replies with `EIO` and leaves the session uninitialized rather than
    +    /// aborting.
    +    #[test]
    +    fn dispatch_init_unoffered_flags_fails() {
    +        let session = Session::new(GreedyInitFs {
    +            extra_want: 1 << 30,
    +            extra_want2: 0,
    +        });
    +        let mut sender = CapturingSender::default();
    +        session.dispatch(Request::new(FUSE_INIT_REQUEST).unwrap(), &mut sender, None);
    +        assert_eq!(reply_error(&sender), -lx::EIO);
    +        assert!(!session.is_initialized());
    +        session.save_state().validate().unwrap();
    +
    +        // Extended init where the client offers FUSE_INIT_EXT with flags2 = 0,
    +        // and the file system sets an unoffered want2 bit.
    +        let session = Session::new(GreedyInitFs {
    +            extra_want: 0,
    +            extra_want2: 1 << 10,
    +        });
    +        let mut sender = CapturingSender::default();
    +        let req = make_init_request(7, 39, 131072, FUSE_INIT_EXT, 0);
    +        session.dispatch(Request::new(req.as_slice()).unwrap(), &mut sender, None);
    +        assert_eq!(reply_error(&sender), -lx::EIO);
    +        assert!(!session.is_initialized());
    +        session.save_state().validate().unwrap();
    +    }
    +
    +    /// A file system whose `init` replaces `*info` via `SessionInfoState` to
    +    /// forge `capable` / `capable2`.
    +    struct ForgingInitFs {
    +        extra_want: u32,
    +    }
    +
    +    impl Fuse for ForgingInitFs {
    +        fn init(&self, info: &mut SessionInfo) {
    +            let mut forged = crate::SessionInfoState::from(*info);
    +            forged.capable = !0;
    +            forged.capable2 = !0;
    +            forged.want |= self.extra_want;
    +            *info = SessionInfo::from(forged);
    +        }
    +    }
    +
    +    /// Replacing `*info` with `SessionInfo::from(SessionInfoState { .. })` in
    +    /// `init` cannot bypass capability validation or overwrite negotiated
    +    /// client capability state.
    +    #[test]
    +    fn dispatch_init_forged_capable_via_session_info_state_fails() {
    +        let session = Session::new(ForgingInitFs {
    +            extra_want: 1 << 30,
    +        });
    +        let mut sender = CapturingSender::default();
    +        session.dispatch(Request::new(FUSE_INIT_REQUEST).unwrap(), &mut sender, None);
    +        assert_eq!(reply_error(&sender), -lx::EIO);
    +        assert!(!session.is_initialized());
    +        session.save_state().validate().unwrap();
    +
    +        let session = Session::new(ForgingInitFs { extra_want: 0 });
    +        let mut sender = CapturingSender::default();
    +        let req = make_init_request(7, 39, 131072, FUSE_INIT_EXT, 0);
    +        session.dispatch(Request::new(req.as_slice()).unwrap(), &mut sender, None);
    +        assert!(session.is_initialized());
    +        let saved = session.save_state();
    +        saved.validate().unwrap();
    +        assert_eq!(saved.info.capable, FUSE_INIT_EXT);
    +        assert_eq!(saved.info.capable2, 0);
    +    }
     }
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