Re: [patch 016/104] epoll: introduce resource usage limits

Davide Libenzi
2009-01-28T06:57:53Z

On Tue, 27 Jan 2009, Davide Libenzi wrote:

> Or, like Willy said, make (for -stable) the default unlimited, and
> let sysadmins to put the bounds if they feel the DoS can apply to them.

Whose patch follows ...

- Davide

---
fs/eventpoll.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

Index: linux-2.6.mod/fs/eventpoll.c
===================================================================
--- linux-2.6.mod.orig/fs/eventpoll.c 2009-01-27 22:40:23.000000000 -0800
+++ linux-2.6.mod/fs/eventpoll.c 2009-01-27 22:52:41.000000000 -0800
@@ -220,9 +220,9 @@
* Configuration options available inside /proc/sys/fs/epoll/
*/
/* Maximum number of epoll devices, per user */
-static int max_user_instances __read_mostly;
+static int max_user_instances __read_mostly = INT_MAX;
/* Maximum number of epoll watched descriptors, per user */
-static int max_user_watches __read_mostly;
+static int max_user_watches __read_mostly = INT_MAX;

/*
* This mutex is used to serialize ep_free() and eventpoll_release_file().
@@ -721,8 +721,7 @@

user = get_current_user();
error = -EMFILE;
- if (unlikely(atomic_read(&user->epoll_devs) >=
- max_user_instances))
+ if (atomic_read(&user->epoll_devs) >= max_user_instances)
goto free_uid;
error = -ENOMEM;
ep = kzalloc(sizeof(*ep), GFP_KERNEL);
@@ -897,8 +896,7 @@
struct epitem *epi;
struct ep_pqueue epq;

- if (unlikely(atomic_read(&ep->user->epoll_watches) >=
- max_user_watches))
+ if (atomic_read(&ep->user->epoll_watches) >= max_user_watches)
return -ENOSPC;
if (!(epi = kmem_cache_alloc(epi_cache, GFP_KERNEL)))
return -ENOMEM;
@@ -1416,13 +1414,6 @@

static int __init eventpoll_init(void)
{
- struct sysinfo si;
-
- si_meminfo(&si);
- max_user_instances = 128;
- max_user_watches = (((si.totalram - si.totalhigh) / 32) << PAGE_SHIFT) /
- EP_ITEM_COST;
-
/* Initialize the structure used to perform safe poll wait head wake ups */
ep_nested_calls_init(&poll_safewake_ncalls);