fs/close: move inode to last to void race condition

race condition:

A Thread:                                    B Thread:
close
file_close
filep->inode = NULL
                         context switch
	               ------------------->  open to alloc same fd
                                             read from IO
filep->f_tag = 0       <-------------------
filep->f_san = 0       ------------------->  ioctl(fd, ...)
                                             fdcheck trigger assert

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1
2025-04-25 11:07:05 +08:00
committed by Xiang Xiao
parent e8d308658d
commit 83967601aa
+4 -4
View File
@@ -162,10 +162,6 @@ int file_close(FAR struct file *filep)
ret = file_close_without_clear(filep);
if (ret >= 0 && filep->f_inode)
{
/* Reset the user file struct instance so that it cannot be reused. */
filep->f_inode = NULL;
#ifdef CONFIG_FDCHECK
filep->f_tag_fdcheck = 0;
#endif
@@ -173,6 +169,10 @@ int file_close(FAR struct file *filep)
#ifdef CONFIG_FDSAN
filep->f_tag_fdsan = 0;
#endif
/* Reset the user file struct instance so that it cannot be reused. */
filep->f_inode = NULL;
}
return ret;