xhh233 opened a new issue, #22270: URL: https://github.com/apache/nuttx/issues/22270
**Mechanism.** An NVS address carries the block in the high bits and the in-block byte offset in the low 16 bits (`NVS_ADDR_OFFS_MASK` = `0xFFFF`). `nvs_startup()` sets `fs->blocksize = CONFIG_MTD_CONFIG_BLOCKSIZE_MULTIPLE * geo.erasesize` without a 16-bit bound, and the block-tail position is stored as `(uint16_t)(fs->blocksize - ate_size)`. When a block exceeds 64 KiB the cast wraps. **Effect.** With a 128 KiB block and `ate_size` 1024, `130048` becomes `64512`, so `nvs_flash_cmp_const()` reads at byte 64512 of the same block instead of byte 130048 — a wrong-offset read. Downstream consequences were not traced. **Location.** `drivers/mtd/mtd_config_nvs.c`, `nvs_startup()`. Tested on NuttX 13.1.0, commit `2b5c0de5e933281c209f954a63b99cf10c132346`. **Trigger.** `CONFIG_MTD_CONFIG_NVS` with `CONFIG_MTD_CONFIG_BLOCKSIZE_MULTIPLE * erasesize > 65536`. Reproduced on a host MTD simulator with `RAMMTD_ERASESIZE=131072`, `RAMMTD_BLOCKSIZE=512`, 4 blocks. **Expected.** `nvs_startup()` rejects an unrepresentable geometry with `-EINVAL` instead of truncating. Exactly 64 KiB (byte offsets `0..65535`) must stay accepted. **Patch.** Return `-EINVAL` when `fs->blocksize > 0xFFFF`. -- 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]
