This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 20fd8f94460 mtd: config: bounds-check the RAM consolidation source
20fd8f94460 is described below
commit 20fd8f94460b16bd6113c60d2d9d586f2f18976d
Author: Honghao Xiang <[email protected]>
AuthorDate: Thu Nov 26 08:49:42 2026 +0000
mtd: config: bounds-check the RAM consolidation source
mtdconfig_ramconsolidate() copies an entry payload from the block buffer
with 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.
Reject such an entry before the destination arithmetic, so no payload byte
outside the buffer is read.
Signed-off-by: Honghao Xiang <[email protected]>
---
drivers/mtd/mtd_config.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/mtd/mtd_config.c b/drivers/mtd/mtd_config.c
index da88ac3b21c..69ac3a46028 100644
--- a/drivers/mtd/mtd_config.c
+++ b/drivers/mtd/mtd_config.c
@@ -650,6 +650,12 @@ static off_t mtdconfig_ramconsolidate(FAR struct
mtdconfig_struct_s *dev)
* fits in the current destination block.
*/
+ if (src_offset + sizeof(hdr) + phdr->len > dev->erasesize)
+ {
+ ret = -EIO;
+ goto errout;
+ }
+
bytes_left_in_block = (dst_block + 1) * dev->erasesize -
dst_offset;
if (bytes_left_in_block < sizeof(*phdr) + phdr->len)