diff -urpN --exclude-from=/home/davej/.exclude bk-linus/fs/fcntl.c linux-2.5/fs/fcntl.c
--- bk-linus/fs/fcntl.c	2002-11-21 02:19:43.000000000 +0000
+++ linux-2.5/fs/fcntl.c	2002-11-21 18:01:55.000000000 +0000
@@ -146,8 +146,13 @@ static int dupfd(struct file *file, int 
 	int ret;
 
 	ret = locate_fd(files, file, start);
-	if (ret < 0) 
+	if (ret < 0) {
+		/* We should return EINVAL instead of EMFILE if the
+		   request for the fd starts beyond the valid range */
+		if (ret==-EMFILE && start>=current->rlim[RLIMIT_NOFILE].rlim_cur)
+			ret = -EINVAL;
 		goto out_putf;
+	}
 	allocate_fd(files, file, ret);
 	return ret;
 
