pussuw commented on code in PR #16361: URL: https://github.com/apache/nuttx/pull/16361#discussion_r2099685831
########## fs/vfs/fs_dup.c: ########## @@ -65,29 +65,32 @@ int file_dup(FAR struct file *filep, int minfd, int flags) uint8_t f_tag_fdcheck; /* File owner fdcheck tag, init to 0 */ #endif - fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true); + /* Pass the close on exec flag to file_allocate */ + + fd2 = file_allocate(g_root_inode, flags, 0, NULL, minfd, true); if (fd2 < 0) { return fd2; } ret = fs_getfilep(fd2, &filep2); #ifdef CONFIG_FDSAN - f_tag_fdsan = filep2->f_tag_fdsan; + f_tag_fdsan = nx_fcntl(fd2, NX_GETTAG_FDSAN, 0); Review Comment: Ok, it seems I have misunderstood how the fdsan tags are inherited (I thought they were inherited always, but they are not!). I'll try to summarize how I think fdsan should behave: - open() -> set fdsan_tag to 0 for the new fd - dup() -> set fdsan_tag to 0 for the new dup'd fd - dup2() / dup3() -> set fdsan_tag to 0, if the file was not open, but preserve fdsan_tag if it was - fdsan_tag is NEVER inherited from another descriptor, i.e. - When fork()'ing, the child does NOT inherit fdsan_tag from parent ? - When dup2()/dup3()'ing newfd does NOT inherit fdsan_tag from oldfd ? Does this sound correct ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org