summaryrefslogtreecommitdiff
path: root/fs/fcntl.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2008-07-27 00:01:20 +0400
committerAl Viro <viro@zeniv.linux.org.uk>2008-07-27 04:53:45 +0400
commit4e1e018ecc6f7bfd10fc75b3ff9715cc8164e0a2 (patch)
tree75404b1269b079a327551f76a9b3f941f5b11a77 /fs/fcntl.c
parent6c5d0512a091480c9f981162227fdb1c9d70e555 (diff)
downloadlinux-4e1e018ecc6f7bfd10fc75b3ff9715cc8164e0a2.tar.xz
[PATCH] fix RLIM_NOFILE handling
* dup2() should return -EBADF on exceeded sysctl_nr_open * dup() should *not* return -EINVAL even if you have rlimit set to 0; it should get -EMFILE instead. Check for orig_start exceeding rlimit taken to sys_fcntl(). Failing expand_files() in dup{2,3}() now gets -EMFILE remapped to -EBADF. Consequently, remaining checks for rlimit are taken to expand_files(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/fcntl.c')
-rw-r--r--fs/fcntl.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 3deec9887089..61d625136813 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -64,11 +64,6 @@ static int locate_fd(unsigned int orig_start, int cloexec)
struct fdtable *fdt;
spin_lock(&files->file_lock);
-
- error = -EINVAL;
- if (orig_start >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
- goto out;
-
repeat:
fdt = files_fdtable(files);
/*
@@ -83,10 +78,6 @@ repeat:
if (start < fdt->max_fds)
newfd = find_next_zero_bit(fdt->open_fds->fds_bits,
fdt->max_fds, start);
-
- error = -EMFILE;
- if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
- goto out;
error = expand_files(files, newfd);
if (error < 0)
@@ -141,13 +132,14 @@ asmlinkage long sys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
spin_lock(&files->file_lock);
if (!(file = fcheck(oldfd)))
goto out_unlock;
- if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
- goto out_unlock;
get_file(file); /* We are now finished with oldfd */
err = expand_files(files, newfd);
- if (err < 0)
+ if (unlikely(err < 0)) {
+ if (err == -EMFILE)
+ err = -EBADF;
goto out_fput;
+ }
/* To avoid races with open() and dup(), we will mark the fd as
* in-use in the open-file bitmap throughout the entire dup2()
@@ -328,6 +320,8 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
switch (cmd) {
case F_DUPFD:
case F_DUPFD_CLOEXEC:
+ if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
+ break;
get_file(filp);
err = dupfd(filp, arg, cmd == F_DUPFD_CLOEXEC);
break;