diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-05-05 09:45:16 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2022-05-05 09:45:16 +0000 |
commit | a1a0ee3f10732d93e25a72d8a8b4f97935bb2fb3 (patch) | |
tree | 624f9d75f59ac994fb377f688a21de2fa9521129 /sys/kern/kern_time.c | |
parent | 5c804a2c4e0384e439c9c1d6347382f51b0efa13 (diff) |
Using mutex initializer for static variable does not compile with
witness. Make ratecheck mutex global.
Reported-by: syzbot+9864ba1338526d0e8aca@syzkaller.appspotmail.com
Diffstat (limited to 'sys/kern/kern_time.c')
-rw-r--r-- | sys/kern/kern_time.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 385d47b4d00..ddc4421445f 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.155 2022/05/04 21:24:33 bluhm Exp $ */ +/* $OpenBSD: kern_time.c,v 1.156 2022/05/05 09:45:15 bluhm Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -36,6 +36,7 @@ #include <sys/resourcevar.h> #include <sys/kernel.h> #include <sys/systm.h> +#include <sys/mutex.h> #include <sys/rwlock.h> #include <sys/proc.h> #include <sys/ktrace.h> @@ -775,6 +776,8 @@ itimerdecr(struct itimerspec *itp, long nsec) return (0); } +struct mutex ratecheck_mtx = MUTEX_INITIALIZER(IPL_HIGH); + /* * ratecheck(): simple time-based rate-limit checking. see ratecheck(9) * for usage and rationale. @@ -782,13 +785,12 @@ itimerdecr(struct itimerspec *itp, long nsec) int ratecheck(struct timeval *lasttime, const struct timeval *mininterval) { - static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH); struct timeval tv, delta; int rv = 0; getmicrouptime(&tv); - mtx_enter(&mtx); + mtx_enter(&ratecheck_mtx); timersub(&tv, lasttime, &delta); /* @@ -800,24 +802,25 @@ ratecheck(struct timeval *lasttime, const struct timeval *mininterval) *lasttime = tv; rv = 1; } - mtx_leave(&mtx); + mtx_leave(&ratecheck_mtx); return (rv); } +struct mutex ppsratecheck_mtx = MUTEX_INITIALIZER(IPL_HIGH); + /* * ppsratecheck(): packets (or events) per second limitation. */ int ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps) { - static struct mutex mtx = MUTEX_INITIALIZER(IPL_HIGH); struct timeval tv, delta; int rv; microuptime(&tv); - mtx_enter(&mtx); + mtx_enter(&ppsratecheck_mtx); timersub(&tv, lasttime, &delta); /* @@ -846,7 +849,7 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps) if (*curpps + 1 > *curpps) *curpps = *curpps + 1; - mtx_leave(&mtx); + mtx_leave(&ppsratecheck_mtx); return (rv); } |