nuttx/fs/romfs
yi chen b9c9c238e8 fs/romfs: reject negative resulting position in romfs_seek()
romfs_seek() clamps the computed position to the file size when it
exceeds rf_size, but never checks for a negative result. lseek(fd,
offset, SEEK_SET/SEEK_CUR/SEEK_END) with an offset that produces a
negative position (e.g. a negative SEEK_SET offset, or a SEEK_CUR/
SEEK_END offset more negative than the current position/file size)
is written straight into filep->f_pos.

The subsequent romfs_read() computes
`rf->rf_startoffset + filep->f_pos` into a uint32_t, so a negative
f_pos wraps around to a huge unsigned offset, and romfs_hwread()'s
XIP path memcpy()s from rm_xipbase plus that offset -- an
out-of-bounds read far past the mapped flash region.

Add the same "if (position < 0) return -EINVAL" guard already used
by fs/fat/fs_fat32.c's seek function, before the existing
end-of-file clamp.

Signed-off-by: yi chen <94xhn1@gmail.com>
Assisted-by: Claude:claude-sonnet-5
2026-08-21 02:20:33 +08:00
..
CMakeLists.txt fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
fs_romfs.c fs/romfs: reject negative resulting position in romfs_seek() 2026-08-21 02:20:33 +08:00
fs_romfs.h Revert "romfs:extend romfs to enable write" 2025-12-24 07:41:28 -03:00
fs_romfsutil.c fs/romfs: fix node cache overflow in directories with >256 entries 2026-08-11 10:53:19 +08:00
Kconfig fs: add fs dump in ROMFS/LITTLEFS 2026-01-19 16:40:57 +08:00
Make.defs fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00