summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/fcntl.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 9679fcbdeaa..ce12a688511 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -139,8 +139,13 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
if (!(file = fcheck(oldfd)))
goto out_unlock;
err = newfd;
- if (newfd == oldfd)
+ if (unlikely(newfd == oldfd)) {
+ if (flags & O_CLOEXEC) {
+ fdt = files_fdtable(files);
+ FD_SET(newfd, fdt->close_on_exec);
+ }
goto out_unlock;
+ }
err = -EBADF;
if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
goto out_unlock;