aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2013-10-21 16:46:12 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2013-10-21 16:46:12 +0000
commit85a0ddfd0b269f9527883973092c457f04c1af19 (patch)
tree04786befd82e74b0298aa6139cca4192ba215854 /lib
parent9110db818a1e36cffed5208b6d005d9c1b84236a (diff)
Add a resource limit for the total number of kqueues available to the
user. Kqueue now saves the ucred of the allocating thread, to correctly decrement the counter on close. Under some specific and not real-world use scenario for kqueue, it is possible for the kqueues to consume memory proportional to the square of the number of the filedescriptors available to the process. Limit allows administrator to prevent the abuse. This is kernel-mode side of the change, with the user-mode enabling commit following. Reported and tested by: pho Discussed with: jmg Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
Notes
svn path=/head/; revision=256850
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/sys/getrlimit.22
-rw-r--r--lib/libutil/login_class.31
-rw-r--r--lib/libutil/login_class.c1
3 files changed, 4 insertions, 0 deletions
diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2
index 35198bce3062..1f84bfb0f0e8 100644
--- a/lib/libc/sys/getrlimit.2
+++ b/lib/libc/sys/getrlimit.2
@@ -108,6 +108,8 @@ Please see
for a complete description of this sysctl.
.It Dv RLIMIT_NPTS
The maximum number of pseudo-terminals created by this user id.
+.It Dv RLIMIT_KQUEUES
+The maximum number of kqueues created by this user id.
.El
.Pp
A resource limit is specified as a soft limit and a hard limit.
diff --git a/lib/libutil/login_class.3 b/lib/libutil/login_class.3
index 62a65f20c799..75f361481c81 100644
--- a/lib/libutil/login_class.3
+++ b/lib/libutil/login_class.3
@@ -118,6 +118,7 @@ sbsize RLIMIT_SBSIZE
vmemoryuse RLIMIT_VMEM
pseudoterminals RLIMIT_NPTS
swapuse RLIMIT_SWAP
+kqueues RLIMIT_KQUEUES
.Ed
.It LOGIN_SETPRIORITY
Set the scheduling priority for the current process based on the
diff --git a/lib/libutil/login_class.c b/lib/libutil/login_class.c
index 263044f446a9..39cce12f7f60 100644
--- a/lib/libutil/login_class.c
+++ b/lib/libutil/login_class.c
@@ -66,6 +66,7 @@ static struct login_res {
{ "vmemoryuse", login_getcapsize, RLIMIT_VMEM },
{ "pseudoterminals", login_getcapnum, RLIMIT_NPTS },
{ "swapuse", login_getcapsize, RLIMIT_SWAP },
+ { "kqueues", login_getcapsize, RLIMIT_KQUEUES },
{ NULL, 0, 0 }
};