summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_proc.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2005-03-10 17:26:10 +0000
committertedu <tedu@openbsd.org>2005-03-10 17:26:10 +0000
commitda90d235d9a0994d7ea5dba99a7c0b53d9268201 (patch)
treeae3ce9b59cb6dcda03d98de35746389a343cd77e /sys/kern/kern_proc.c
parentAvoid crash on finalization. We have been using this diff (diff)
downloadwireguard-openbsd-da90d235d9a0994d7ea5dba99a7c0b53d9268201.tar.xz
wireguard-openbsd-da90d235d9a0994d7ea5dba99a7c0b53d9268201.zip
split out uidinfo from kern_proc.c private, use it to store lock count,
restrict lock count per uid to a global limit, add sysctl to adjust limit. this prevents a user from creating too many locks. problem noticed by devon o'dell. ok deraadt miod pedro
Diffstat (limited to 'sys/kern/kern_proc.c')
-rw-r--r--sys/kern/kern_proc.c54
1 files changed, 22 insertions, 32 deletions
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 962fe11dea4..2ba584ca631 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_proc.c,v 1.24 2004/12/26 21:22:13 miod Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.25 2005/03/10 17:26:10 tedu Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
@@ -49,14 +49,6 @@
#include <sys/signalvar.h>
#include <sys/pool.h>
-/*
- * Structure associated with user caching.
- */
-struct uidinfo {
- LIST_ENTRY(uidinfo) ui_hash;
- uid_t ui_uid;
- long ui_proccnt;
-};
#define UIHASH(uid) (&uihashtbl[(uid) & uihash])
LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
u_long uihash; /* size of hash table - 1 */
@@ -115,38 +107,36 @@ procinit()
* Change the count associated with number of processes
* a given user is using.
*/
-int
-chgproccnt(uid, diff)
- uid_t uid;
- int diff;
+struct uidinfo *
+uid_find(uid_t uid)
{
- register struct uidinfo *uip;
- register struct uihashhead *uipp;
+ struct uidinfo *uip;
+ struct uihashhead *uipp;
uipp = UIHASH(uid);
LIST_FOREACH(uip, uipp, ui_hash)
if (uip->ui_uid == uid)
break;
- if (uip) {
- uip->ui_proccnt += diff;
- if (uip->ui_proccnt > 0)
- return (uip->ui_proccnt);
- if (uip->ui_proccnt < 0)
- panic("chgproccnt: procs < 0");
- LIST_REMOVE(uip, ui_hash);
- FREE(uip, M_PROC);
- return (0);
- }
- if (diff <= 0) {
- if (diff == 0)
- return(0);
- panic("chgproccnt: lost user");
- }
+ if (uip)
+ return (uip);
MALLOC(uip, struct uidinfo *, sizeof(*uip), M_PROC, M_WAITOK);
+ bzero(uip, sizeof(*uip));
LIST_INSERT_HEAD(uipp, uip, ui_hash);
uip->ui_uid = uid;
- uip->ui_proccnt = diff;
- return (diff);
+
+ return (uip);
+}
+
+int
+chgproccnt(uid_t uid, int diff)
+{
+ struct uidinfo *uip;
+
+ uip = uid_find(uid);
+ uip->ui_proccnt += diff;
+ if (uip->ui_proccnt < 0)
+ panic("chgproccnt: procs < 0");
+ return (uip->ui_proccnt);
}
/*