nuttx/fs
dongjiuzhu1 cd8e3e18a8 fs/file: add reference count protection for stack-allocated file structures
Issue:
When using a stack-allocated file structure, the sequence:
1. file_open() initializes the stack file structure
2. file_mmap() creates memory mapping and increments reference count
3. file_munmap() decrements reference count and may free the file structure
4. file_close() attempts to close already freed structure → crash

Root cause:
The memory mapping operations (fs_reffilep/fs_putfilep) manage reference counts
independently and can free the stack-allocated file structure prematurely.

Solution:
- Add reference count protection during file_open() for stack-allocated files
- Clear reference count appropriately during file_close()
- This ensures the file structure remains valid throughout its lifetime

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2026-01-01 17:06:17 +08:00
..
aio fs/file: unify prefix about file_xxx api, like file_open, file_ioctl 2025-06-12 18:12:42 +08:00
binfs fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
cromfs fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
driver fs/fs.h: Add register_driver_with_size function 2025-11-13 08:57:52 -03:00
event fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00
fat fs/fat: Ignore multiple consecutive slashes in long file names 2025-11-27 22:26:56 +08:00
hostfs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
inode fs/fs_files: restore fd before calling fdlist_install 2025-06-26 09:31:14 -03:00
littlefs littlefs: fix statfs underflow during active writes 2025-12-29 14:23:04 +08:00
mmap fs/mmap/Kconfig: fix reference to non-existent readme 2025-10-11 17:07:51 -04:00
mnemofs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
mount fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00
mqueue fs/mqueue: fix inverted 'created' flag in file_mq_vopen 2025-12-31 02:27:37 +08:00
nfs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
nxffs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
partition style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
procfs mm:use Kconfig to control sequence number to save memory 2025-12-20 09:47:22 -03:00
romfs Revert "romfs:extend romfs to enable write" 2025-12-24 07:41:28 -03:00
rpmsgfs sched/sleep: replace all Signal-based sleep implement to Scheduled sleep 2025-10-17 14:05:02 +08:00
semaphore bugfix:the inode may have been removed by other core in SMP 2025-12-16 16:02:46 -03:00
shm fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00
smartfs fs/smartfs: Fix a fatal bug about sector writing after seek 2025-06-13 20:42:36 +08:00
socket fs/vfs: Separate file descriptors from file descriptions 2025-06-12 18:12:42 +08:00
spiffs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
tmpfs tmpfs:fix memoryleak of tmpfs_opendir 2025-12-22 11:02:10 -05:00
unionfs style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
userfs fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
v9fs refactor: fix spelling in private field names 2025-05-24 09:44:22 -03:00
vfs fs/file: add reference count protection for stack-allocated file structures 2026-01-01 17:06:17 +08:00
zipfs fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
CMakeLists.txt fs: migrate to SPDX identifier 2024-11-06 01:58:54 +08:00
fs_heap.c fs_heap:add fs_heap_mallinfo_task 2025-01-15 17:12:50 +08:00
fs_heap.h fs_heap:add fs_heap_mallinfo_task 2025-01-15 17:12:50 +08:00
fs_initialize.c fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00
Kconfig fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00
Makefile fs: Move inotify.c from fs/notify/ to fs/vfs/ 2025-06-23 18:17:10 -03:00