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

オープン
#1,630 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
52/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
security

調査の方向性

Start by reading dispatch_init in vm/devices/support/fs/fuse/src/session.rs and Fuse::init in src/lib.rs, then compare SessionInfo with SessionInfoState in src/session/saved_state.rs. Run the two named cargo nextest filters in -p fuse to observe the panic and the forged-capability success. Done means unoffered or forged FUSE_INIT flags fail with -EIO instead of panicking, and both regression tests pass.

索引モデルが issue の本文から書いたものです。

説明

area: openvmm

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.

主要言語
Rust
スター
848
フォーク
63
平均マージ
13時間 37分
マージ済み PR(30日)
571

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/nvx のほかの issue

microsoft/nvx の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。