diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2012-08-12 16:17:59 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-09-26 21:08:53 -0400 |
commit | f33ff9927f42045116d738ee47ff7bc59f739bd7 (patch) | |
tree | 917e0d7c10392a884a0aeda8733bdd2ef8e2c105 /fs | |
parent | 352e3b249284235e00745f3e71fc348b913e5deb (diff) |
take rlimit check to callers of expand_files()
... except for one in android, where the check is different
and already done in caller. No need to recalculate rlimit
many times in alloc_fd() either.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fcntl.c | 3 | ||||
-rw-r--r-- | fs/file.c | 16 |
2 files changed, 12 insertions, 7 deletions
diff --git a/fs/fcntl.c b/fs/fcntl.c index 887b5ba8c9b5..08e6af5c1b1f 100644 --- a/fs/fcntl.c +++ b/fs/fcntl.c | |||
@@ -64,6 +64,9 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) | |||
64 | if (unlikely(oldfd == newfd)) | 64 | if (unlikely(oldfd == newfd)) |
65 | return -EINVAL; | 65 | return -EINVAL; |
66 | 66 | ||
67 | if (newfd >= rlimit(RLIMIT_NOFILE)) | ||
68 | return -EMFILE; | ||
69 | |||
67 | spin_lock(&files->file_lock); | 70 | spin_lock(&files->file_lock); |
68 | err = expand_files(files, newfd); | 71 | err = expand_files(files, newfd); |
69 | file = fcheck(oldfd); | 72 | file = fcheck(oldfd); |
@@ -251,13 +251,6 @@ int expand_files(struct files_struct *files, int nr) | |||
251 | 251 | ||
252 | fdt = files_fdtable(files); | 252 | fdt = files_fdtable(files); |
253 | 253 | ||
254 | /* | ||
255 | * N.B. For clone tasks sharing a files structure, this test | ||
256 | * will limit the total number of files that can be opened. | ||
257 | */ | ||
258 | if (nr >= rlimit(RLIMIT_NOFILE)) | ||
259 | return -EMFILE; | ||
260 | |||
261 | /* Do we need to expand? */ | 254 | /* Do we need to expand? */ |
262 | if (nr < fdt->max_fds) | 255 | if (nr < fdt->max_fds) |
263 | return 0; | 256 | return 0; |
@@ -431,6 +424,7 @@ int alloc_fd(unsigned start, unsigned flags) | |||
431 | { | 424 | { |
432 | struct files_struct *files = current->files; | 425 | struct files_struct *files = current->files; |
433 | unsigned int fd; | 426 | unsigned int fd; |
427 | unsigned end = rlimit(RLIMIT_NOFILE); | ||
434 | int error; | 428 | int error; |
435 | struct fdtable *fdt; | 429 | struct fdtable *fdt; |
436 | 430 | ||
@@ -444,6 +438,14 @@ repeat: | |||
444 | if (fd < fdt->max_fds) | 438 | if (fd < fdt->max_fds) |
445 | fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd); | 439 | fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, fd); |
446 | 440 | ||
441 | /* | ||
442 | * N.B. For clone tasks sharing a files structure, this test | ||
443 | * will limit the total number of files that can be opened. | ||
444 | */ | ||
445 | error = -EMFILE; | ||
446 | if (fd >= end) | ||
447 | goto out; | ||
448 | |||
447 | error = expand_files(files, fd); | 449 | error = expand_files(files, fd); |
448 | if (error < 0) | 450 | if (error < 0) |
449 | goto out; | 451 | goto out; |