xhh233 opened a new pull request, #22385: URL: https://github.com/apache/nuttx/pull/22385
## Summary `mtdconfig_ramconsolidate()` copies an entry payload with ```c mtdconfig_writebytes(dev, dst_offset, &pbuf[src_offset + sizeof(hdr)], phdr->len) ``` using the length stored on flash. It verifies that the payload fits in the destination block, but never that it fits in the source block, so a malformed active entry makes the copy read past the `kmm_malloc(dev->erasesize)` buffer. On the pinned 13.1.0 source (sha256 `30b2de5e…`), an active header at offset 499 with `len = 200` produces an ASan `READ of size 119` past a 512-byte buffer. The new check rejects such an entry before the destination arithmetic and before any payload byte is read, taking the existing `errout` path. ## Impact Only malformed (or corrupted) configuration images are affected; well-formed entries consolidate exactly as before. This is deliberately independent of #22379 (error propagation) — it stops the out-of-bounds read on its own. ## Testing Host harness with ASan on the pinned 13.1.0 source, geometry `blocksize=128`, `erasesize=512`, `neraseblocks=2`, image with 31 well-formed active entries followed by an active header at offset 499 with `len=200`: * before: `heap-buffer-overflow`, `READ of size 119` at `mtd_config.c:685`, past a 512-byte region allocated at `:579` * after: no ASan report; the entry is rejected The harness models the driver logic at the MTD boundary; no board or QEMU run is claimed. ## AI declaration AI tools were used: OpenAI GPT (codex CLI) for review of the claim and of the patch before submission, and opencode agents driving DeepSeek models for source analysis, the harness and drafting. The final change was reviewed by the contributor and verified with the ASan host run above. Issue reference: #22319. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
