public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2.4.33.2] enforce RLIMIT_NOFILE in poll()
@ 2006-09-01  1:06 Chris Snook
  2006-09-01  3:48 ` Willy Tarreau
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Snook @ 2006-09-01  1:06 UTC (permalink / raw)
  To: linux-kernel; +Cc: willy

From: Chris Snook <csnook@redhat.com>

POSIX states that poll() shall fail with EINVAL if nfds > OPEN_MAX.  In this
context, POSIX is referring to sysconf(OPEN_MAX), which is the value of
current->rlim[RLIMIT_NOFILE].rlim_cur, not the compile-time constant which
happens to be named OPEN_MAX.  The current code will permit polling up to 1024
file descriptors even if RLIMIT_NOFILE is less than 1024, which POSIX forbids.
 The current code also breaks polling greater than 1024 file descriptors if
the process has less than 1024 valid descriptors, even if RLIMIT_NOFILE >
1024.  While it is silly to poll duplicate or invalid file descriptors, POSIX
permits this, and it worked circa 2.4.18, and currently works up to 1024.
This patch directly checks the RLIMIT_NOFILE value, and permits exactly what
POSIX suggests, no more, no less.

Signed-off-by: Chris Snook <csnook@redhat.com>
---

diff -urNp linux-2.4.33.2-orig/fs/select.c linux-2.4.33.2-patch/fs/select.c
--- linux-2.4.33.2-orig/fs/select.c	2006-08-22 16:13:54.000000000 -0400
+++ linux-2.4.33.2-patch/fs/select.c	2006-08-31 13:43:39.000000000 -0400
@@ -417,7 +417,7 @@ asmlinkage long sys_poll(struct pollfd *
 	int nchunks, nleft;

 	/* Do a sanity check on nfds ... */
-	if (nfds > current->files->max_fdset && nfds > OPEN_MAX)
+	if (nfds > current->rlim[RLIMIT_NOFILE].rlim_cur)
 		return -EINVAL;

 	if (timeout) {


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-09-01 22:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-01  1:06 [PATCH 2.4.33.2] enforce RLIMIT_NOFILE in poll() Chris Snook
2006-09-01  3:48 ` Willy Tarreau
2006-09-01  4:25   ` Vadim Lobanov
2006-09-01  6:08     ` Chris Snook
2006-09-01 16:03     ` Chris Snook
2006-09-01 19:31       ` Willy Tarreau
2006-09-01 21:24         ` Chris Snook
2006-09-01 20:04           ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox