[Patch] Limit max_user_watches to prevent integer overflow.

From: Robin Holt
Date: Sat Oct 02 2010 - 07:41:07 EST


Subject: [Patch] Limit max_user_watches to prevent integer overflow.

On a 16TB machine, max_user_watches has an integer overflow. Limit it
to INT_MAX.

Signed-off-by: Robin Holt <holt@xxxxxxx>
To: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
To: Davide Libenzi <davidel@xxxxxxxxxxxxxxx>
To: linux-kernel@xxxxxxxxxxxxxxx
To: Pekka Enberg <penberg@xxxxxxxxxxxxxx>

---

fs/eventpoll.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

Index: pv1010933/fs/eventpoll.c
===================================================================
--- pv1010933.orig/fs/eventpoll.c 2010-10-02 06:35:37.000000000 -0500
+++ pv1010933/fs/eventpoll.c 2010-10-02 06:38:06.479823590 -0500
@@ -1415,13 +1415,14 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd,
static int __init eventpoll_init(void)
{
struct sysinfo si;
+ long limit;

si_meminfo(&si);
/*
* Allows top 4% of lomem to be allocated for epoll watches (per user).
*/
- max_user_watches = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) /
- EP_ITEM_COST;
+ limit = (((si.totalram - si.totalhigh) / 25) << PAGE_SHIFT) / EP_ITEM_COST;
+ max_user_watches = min_t(long, limit, INT_MAX);

/* Initialize the structure used to perform safe poll wait head wake ups */
ep_nested_calls_init(&poll_safewake_ncalls);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/