diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index a574a6e79a5..e61f432c52b 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -209,6 +209,13 @@ static int nx_dup3_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2, int flags) { FAR struct filelist *list; + FAR struct file *filep; +#ifdef CONFIG_FDCHECK + uint8_t f_tag_fdcheck; +#endif +#ifdef CONFIG_FDSAN + uint64_t f_tag_fdsan; +#endif int count; int ret; @@ -241,14 +248,36 @@ static int nx_dup3_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2, } } + filep = files_fget(list, fd2); + if (filep == NULL) + { + return -EBADF; + } + +#ifdef CONFIG_FDSAN + f_tag_fdsan = filep->f_tag_fdsan; +#endif + +#ifdef CONFIG_FDCHECK + f_tag_fdcheck = filep->f_tag_fdcheck; +#endif + /* Perform the dup3 operation */ - ret = file_dup3(files_fget(list, fd1), files_fget(list, fd2), flags); + ret = file_dup3(files_fget(list, fd1), filep, flags); if (ret < 0) { return ret; } +#ifdef CONFIG_FDSAN + filep->f_tag_fdsan = f_tag_fdsan; +#endif + +#ifdef CONFIG_FDCHECK + filep->f_tag_fdcheck = f_tag_fdcheck; +#endif + #ifdef CONFIG_FDCHECK return fdcheck_protect(fd2); #else diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c index c7baf3a28f1..f5917456e77 100644 --- a/fs/vfs/fs_dup2.c +++ b/fs/vfs/fs_dup2.c @@ -164,6 +164,16 @@ int file_dup3(FAR struct file *filep1, FAR struct file *filep2, int flags) } } + /* Copy tag */ + +#ifdef CONFIG_FDSAN + filep2->f_tag_fdsan = filep1->f_tag_fdsan; +#endif + +#ifdef CONFIG_FDCHECK + filep2->f_tag_fdcheck = filep1->f_tag_fdcheck; +#endif + return OK; }