Commit 03d5d52e authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Remove unneeded fcntl check

The NR_OPEN check in F_DUPFD is unneeded.  viro says:

"We check the limits in locate_fd() (called by dupfd()).  Check for NR_OPEN
can (and should) be dropped - locate_fd() will never go beyond that
(expand_fd() will check it and refuse to go).

"IOW, simply lose the check.  We _might_ want to check signedness, but that's
it (IOW, check that arg will fit into 0..MAX_INT; second argument of dupfd()
is an int).  OTOH, we might actually make dupfd() et.al.  take unsigned long
and kill that crap completely."

And indeed, the signedness is suspicious, so make various things in there
unsigned too.
parent 3493e0ab
...@@ -80,11 +80,11 @@ static int expand_files(struct files_struct *files, int nr) ...@@ -80,11 +80,11 @@ static int expand_files(struct files_struct *files, int nr)
*/ */
static int locate_fd(struct files_struct *files, static int locate_fd(struct files_struct *files,
struct file *file, int orig_start) struct file *file, unsigned int orig_start)
{ {
unsigned int newfd; unsigned int newfd;
unsigned int start;
int error; int error;
int start;
error = -EINVAL; error = -EINVAL;
if (orig_start >= current->rlim[RLIMIT_NOFILE].rlim_cur) if (orig_start >= current->rlim[RLIMIT_NOFILE].rlim_cur)
...@@ -129,7 +129,7 @@ static int locate_fd(struct files_struct *files, ...@@ -129,7 +129,7 @@ static int locate_fd(struct files_struct *files,
return error; return error;
} }
static int dupfd(struct file *file, int start) static int dupfd(struct file *file, unsigned int start)
{ {
struct files_struct * files = current->files; struct files_struct * files = current->files;
int fd; int fd;
...@@ -286,10 +286,8 @@ static long do_fcntl(unsigned int fd, unsigned int cmd, ...@@ -286,10 +286,8 @@ static long do_fcntl(unsigned int fd, unsigned int cmd,
switch (cmd) { switch (cmd) {
case F_DUPFD: case F_DUPFD:
if (arg < NR_OPEN) { get_file(filp);
get_file(filp); err = dupfd(filp, arg);
err = dupfd(filp, arg);
}
break; break;
case F_GETFD: case F_GETFD:
err = get_close_on_exec(fd); err = get_close_on_exec(fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment