Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Return the right error value when dup[23]() newfd argument is too large

Jack Lin reports that the error return from dup3() for the RLIMIT_NOFILE
case changed incorrectly after 3.6.

The culprit is commit f33ff9927f42 ("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 <linliangjie@huawei.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
[ Noted more bugs, wrote proper changelog, fixed up typos - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Al Viro and committed by
Linus Torvalds
08f05c49 2df4f261

+2 -2
+2 -2
fs/file.c
··· 900 900 return __close_fd(files, fd); 901 901 902 902 if (fd >= rlimit(RLIMIT_NOFILE)) 903 - return -EMFILE; 903 + return -EBADF; 904 904 905 905 spin_lock(&files->file_lock); 906 906 err = expand_files(files, fd); ··· 926 926 return -EINVAL; 927 927 928 928 if (newfd >= rlimit(RLIMIT_NOFILE)) 929 - return -EMFILE; 929 + return -EBADF; 930 930 931 931 spin_lock(&files->file_lock); 932 932 err = expand_files(files, newfd);