mtd: RAM consolidation reads past its block buffer on a malformed entry
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c
調査の方向性
不具合は drivers/mtd/mtd_config.c の mtdconfig_ramconsolidate() にあります。約685行目のペイロードのコピーで、ソース側の境界チェックなしに phdr->len が使われています。直前のヘッダ解析を読んでから、src_offset + sizeof(hdr) + phdr->len <= dev->erasesize を確認するチェックを追加し、失敗したら errout へジャンプしてください。不正なエントリがエラーを返し、CONFIG_MTD_CONFIG_RAM_CONSOLIDATE=1 を指定した ASan ハーネスがオーバーフローを報告しなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Mechanism. mtdconfig_ramconsolidate() allocates pbuf = kmm_malloc(dev->erasesize) (:579) and walks the source entries of one block. At :685 it copies the entry payload with
mtdconfig_writebytes(dev, dst_offset, &pbuf[src_offset + sizeof(hdr)], phdr->len)
using the on-flash phdr->len without checking that src_offset + sizeof(hdr) + phdr->len fits inside dev->erasesize. Destination space is checked; the source bound is not.
Effect. A header at offset 499 with len = 200 passes the header read (499 + 6 = 505 ≤ 512) but starts a 200-byte copy at 505, so 119 bytes are read past the 512-byte pbuf.
Trigger. RAM consolidation processes a malformed active entry. Corrupt flash is a robustness case; this function-level test does not establish that an attacker can supply such an image on a deployed device.
Location. NuttX nuttx-13.1.0, commit 2b5c0de5e933281c209f954a63b99cf10c132346, drivers/mtd/mtd_config.c, sha256 30b2de5e6c7e4fc28df2401d3b6d13926abe84d70274c227efbdb28c12ab6aa3:
| Anchor | Line | Code |
|---|---|---|
| allocation | :579 |
pbuf = kmm_malloc(dev->erasesize); |
| payload copy | :685 |
mtdconfig_writebytes(dev, dst_offset, &pbuf[src_offset + sizeof(hdr)], phdr->len) |
| error exit | :730 |
label errout: |
Line numbers in other renderings differ; the code text locates each anchor.
Evidence. One before/after function-level ASan run, harness geometry blocksize=128, erasesize=512, neraseblocks=2, CONFIG_MTD_CONFIG_RAM_CONSOLIDATE=1, image with 31 well-formed active entries followed by an active header at offset 499 with len=200: before.log reports heap-buffer-overflow, READ of size 119 at mtd_config.c:685, past a 512-byte region allocated at :579; with the patch, returned -5 and no ASan report.
Expected. Consolidation rejects an entry whose declared payload runs past the block end instead of copying it.
Patch. Validate src_offset + sizeof(hdr) + phdr->len <= dev->erasesize before the copy and take the errout path when it does not hold.
- 主要言語
- C
- スター
- 4.1k
- フォーク
- 1.8k
- 平均マージ
- 1日 17時間
- マージ済み PR(30日)
- 900
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/nuttx のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/nuttx#22270 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
apache/nuttx#22171 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Arch: all Arch: arm Area: Build system OS: Linux Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/nuttx#19435 · コメント 9 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Document the isv:HDFGroup Linux package repositories and signing key対応中かも @brtnfld が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
bug status: planned
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ChupathingyCE/chupathingyce#1834 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信