mtd: RAM consolidation reads past its block buffer on a malformed entry
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- c
调研方向
问题出在 drivers/mtd/mtd_config.c 中的 mtdconfig_ramconsolidate():大约第 685 行的 payload 拷贝使用了 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 小时
- 30 天内合并 PR
- 900
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/nuttx 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 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
维护者通常 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 天内回复