nuttx/fs/aio
Xiang Xiao b7d6c8ff41 fs/aio: fix aioc use-after-free and aio_cancel() issues
aioc_decant() frees the AIO container and detaches the aiocbp.  The
I/O workers (aio_read_worker, aio_write_worker, aio_fsync_worker)
called it before signaling completion, so aio_signal() and any code
touching the container afterwards ran on freed memory.  Additionally,
if the caller closed the file early the detached container could be
reused with a stale file reference.  Move aioc_decant() to after
aio_signal() and use aioc->aioc_aiocbp directly in the workers.

aio_cancel() also had two problems: with no aiocbp it looped over
g_aio_pending with a do/while that skipped the list re-entry check, so
a failed work_cancel() on an already running I/O caused an endless
loop; and an invalid fildes only checked 'fildes < 0' instead of
validating the descriptor, so a closed fd was not reported as EBADF.
Use a for-loop that always advances and validate the descriptor with
file_get()/file_put().

Co-developed-by: wushenhui <wushenhui@xiaomi.com>
Signed-off-by: wushenhui <wushenhui@xiaomi.com>
Signed-off-by: tengshuangshuang <tengshuangshuang@xiaomi.com>
2026-09-14 17:12:49 -03:00
..
aio.h
aio_cancel.c fs/aio: fix aioc use-after-free and aio_cancel() issues 2026-09-14 17:12:49 -03:00
aio_fsync.c fs/aio: fix aioc use-after-free and aio_cancel() issues 2026-09-14 17:12:49 -03:00
aio_initialize.c
aio_queue.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
aio_read.c fs/aio: fix aioc use-after-free and aio_cancel() issues 2026-09-14 17:12:49 -03:00
aio_signal.c fs/aio: rework lio_listio() with a lock-protected request list 2026-09-14 17:12:49 -03:00
aio_write.c fs/aio: fix aioc use-after-free and aio_cancel() issues 2026-09-14 17:12:49 -03:00
aioc_contain.c
CMakeLists.txt fs/aio: move lio_listio() to fs/aio 2026-09-14 17:12:49 -03:00
Kconfig fs/aio: add configurable AIO_LISTIO_MAX limit 2026-09-14 17:12:49 -03:00
lio_listio.c fs/aio: add configurable AIO_LISTIO_MAX limit 2026-09-14 17:12:49 -03:00
Make.defs fs/aio: move lio_listio() to fs/aio 2026-09-14 17:12:49 -03:00