From b20d5b49553cdb2cd5369ad103dc7a9078a620a2 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 26 Jul 2008 13:38:19 -0400 Subject: [PATCH] --- yaml --- r: 106384 b: refs/heads/master c: 6c5d0512a091480c9f981162227fdb1c9d70e555 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/fcntl.c | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/[refs] b/[refs] index bed7e9416d71..afcb80b7982c 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 4cc38a1b383f0c6c65a3fef4ff8144e8000e4ec3 +refs/heads/master: 6c5d0512a091480c9f981162227fdb1c9d70e555 diff --git a/trunk/fs/fcntl.c b/trunk/fs/fcntl.c index ce12a6885115..3deec9887089 100644 --- a/trunk/fs/fcntl.c +++ b/trunk/fs/fcntl.c @@ -135,18 +135,12 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags) if ((flags & ~O_CLOEXEC) != 0) return -EINVAL; + if (unlikely(oldfd == newfd)) + return -EINVAL; + spin_lock(&files->file_lock); if (!(file = fcheck(oldfd))) goto out_unlock; - err = newfd; - 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; get_file(file); /* We are now finished with oldfd */ @@ -194,6 +188,14 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags) asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd) { + if (unlikely(newfd == oldfd)) { /* corner case */ + struct files_struct *files = current->files; + rcu_read_lock(); + if (!fcheck_files(files, oldfd)) + oldfd = -EBADF; + rcu_read_unlock(); + return oldfd; + } return sys_dup3(oldfd, newfd, 0); }