OpenSBI mpxy: base_attr_id + attr_count can wrap and bypass range checks

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

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

評価

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

調査の方向性

lib/sbi/sbi_mpxy.c の sbi_mpxy_read_attrs() と sbi_mpxy_write_attrs() における範囲処理を読み、lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c の対応するヘルパーと比較します。呼び出し元が制御する base_attr_id と attr_count の値について、u32 の上限付近をテストします。属性のインデックス処理やコピーが行われる前に、無効なラップアラウンド範囲が拒否されれば完了です。

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

説明

Title: OpenSBI mpxy: base_attr_id + attr_count can wrap and bypass range checks

Current upstream OpenSBI master (checked in a local clone at 6d5b2b9 on 2026-03-21) still computes attribute end IDs in u32 and then uses the result for range checks:

  • lib/sbi/sbi_mpxy.c: sbi_mpxy_read_attrs() and sbi_mpxy_write_attrs()
  • lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c: mpxy_mbox_read_attributes() and mpxy_mbox_write_attributes()

The core pattern is:

u32 end_id = base_attr_id + attr_count - 1;
if (end_id >= MAX_ID)
    return SBI_EBAD_RANGE;

or equivalent. The problem is that both base_attr_id and attr_count are caller-controlled u32 values. When base_attr_id is close to UINT32_MAX and attr_count is greater than 1, the addition wraps before the range check runs. That can make end_id look small even though the requested range is actually huge. In the mpxy helpers, the code then uses attr_id2index(base_attr_id) and copies attributes from or to the array starting at that wrapped index, so the overflowed range check can lead to out-of-bounds access in the message-protocol attribute array.

The current sanity check only validates that attr_count is non-zero and not larger than the shared-memory size in units of ATTR_SIZE. It does not prevent wraparound in base_attr_id + attr_count - 1, so the bug is still present in current head.

Expected behavior: the range calculation should use overflow-safe arithmetic, or the code should explicitly check base_attr_id > MAX - (attr_count - 1) before adding.

Actual behavior: the u32 addition can wrap and allow a bogus range to pass the bounds check, which then drives out-of-bounds attribute indexing/copying.

This looks like a security-relevant memory-safety bug in the OpenSBI mpxy path.

主要言語
C
スター
1.6k
フォーク
734
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

riscv-software-src/opensbi のほかの issue

riscv-software-src/opensbi の issue をすべて見る

似ている issue

C の issue をもっと見る

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

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