lkml.org 
[lkml]   [2011]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] posix-timers: limit the number of posix timers per process v2
Date
From: Andi Kleen <ak@linux.intel.com>

Now this is the main reason I wrote the whole patchkit: previously
there was no limit on the maximum number of POSIX timers a process
could allocate. This limits the amount of unswappable kernel memory
a process can pin down this way.

With the POSIX timer ids being per process we can do this limit
per process now without allowing one process DoSing another.

Uses a rlimit to limit the number of timers.

The 1024 default is completely arbitrary, but seems reasonable
for now.

v2: Use a rlimit instead of sysctl
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
fs/proc/base.c | 1 +
include/asm-generic/resource.h | 4 +++-
include/linux/limits.h | 1 +
kernel/posix-timers.c | 6 ++++++
4 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 5eb0206..229ec4e 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -511,6 +511,7 @@ static const struct limit_names lnames[RLIM_NLIMITS] = {
[RLIMIT_NICE] = {"Max nice priority", NULL},
[RLIMIT_RTPRIO] = {"Max realtime priority", NULL},
[RLIMIT_RTTIME] = {"Max realtime timeout", "us"},
+ [RLIMIT_POSIX_TIMERS] = {"Max number of POSIX timers", "timers"},
};

/* Display limits for a process */
diff --git a/include/asm-generic/resource.h b/include/asm-generic/resource.h
index 61fa862..9fde1b5 100644
--- a/include/asm-generic/resource.h
+++ b/include/asm-generic/resource.h
@@ -45,7 +45,8 @@
0-39 for nice level 19 .. -20 */
#define RLIMIT_RTPRIO 14 /* maximum realtime priority */
#define RLIMIT_RTTIME 15 /* timeout for RT tasks in us */
-#define RLIM_NLIMITS 16
+#define RLIMIT_POSIX_TIMERS 16 /* max number of posix timers/process */
+#define RLIM_NLIMITS 17

/*
* SuS says limits have to be unsigned.
@@ -87,6 +88,7 @@
[RLIMIT_NICE] = { 0, 0 }, \
[RLIMIT_RTPRIO] = { 0, 0 }, \
[RLIMIT_RTTIME] = { RLIM_INFINITY, RLIM_INFINITY }, \
+ [RLIMIT_POSIX_TIMERS] = { POSIX_TIMERS_LIM, POSIX_TIMERS_LIM }, \
}

#endif /* __KERNEL__ */
diff --git a/include/linux/limits.h b/include/linux/limits.h
index 2d0f941..634a445 100644
--- a/include/linux/limits.h
+++ b/include/linux/limits.h
@@ -14,6 +14,7 @@
#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */
+#define POSIX_TIMERS_LIM 1024 /* Number of posix timers process (default) */

#define RTSIG_MAX 32

diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index f832021..9eb0a68 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -567,6 +567,12 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,

it_id_set = IT_ID_SET;
new_timer->it_id = (timer_t) new_timer_id;
+
+ if (new_timer_id >= rlimit(RLIMIT_POSIX_TIMERS)) {
+ error = -EPERM;
+ goto out;
+ }
+
new_timer->it_clock = which_clock;
new_timer->it_overrun = -1;

--
1.7.4.4


\
 
 \ /
  Last update: 2011-09-19 23:51    [W:1.797 / U:0.496 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site