Skip to content

Commit

Permalink
Return the right error value when dup[23]() newfd argument is too large
Browse files Browse the repository at this point in the history
Jack Lin reports that the error return from dup3() for the RLIMIT_NOFILE
case changed incorrectly after 3.6.

The culprit is commit f33ff99 ("take rlimit check to callers of
expand_files()") which when it moved the "return -EMFILE" out to the
caller, didn't notice that the dup3() had special code to turn the
EMFILE return into EBADF.

The replace_fd() helper that got added later then inherited the bug too.

Reported-by: Jack Lin <[email protected]>
Signed-off-by: Al Viro <[email protected]>
[ Noted more bugs, wrote proper changelog, fixed up typos - Linus ]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Al Viro authored and torvalds committed Oct 31, 2012
1 parent 2df4f26 commit 08f05c4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
return __close_fd(files, fd);

if (fd >= rlimit(RLIMIT_NOFILE))
return -EMFILE;
return -EBADF;

spin_lock(&files->file_lock);
err = expand_files(files, fd);
Expand All @@ -926,7 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
return -EINVAL;

if (newfd >= rlimit(RLIMIT_NOFILE))
return -EMFILE;
return -EBADF;

spin_lock(&files->file_lock);
err = expand_files(files, newfd);
Expand Down

0 comments on commit 08f05c4

Please sign in to comment.