You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mtd: config NVS truncates the block-tail offset to 16 bits #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.
Activity
xhh233 commentedon Nov 24, 2026
Candidate fix:
mtd/config_nvs: validate block size and count before buffer allocation