diff options
author | cperciva <cperciva@FreeBSD.org> | 2009-03-23 00:00:50 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2009-03-23 00:00:50 +0000 |
commit | b7238dced470f241b46f4256b6cb23f37d257885 (patch) | |
tree | 4cbc1fe81db80b307ba15e4804fb825c4d94e902 /sys/kern | |
parent | 106f32b27d5cca98bf5757cbc38a11036042aa71 (diff) | |
download | FreeBSD-src-b7238dced470f241b46f4256b6cb23f37d257885.zip FreeBSD-src-b7238dced470f241b46f4256b6cb23f37d257885.tar.gz |
Correctly sanity-check timer IDs. [SA-09:06]
Limit the size of malloced buffer when dumping environment
variables. [EN-09:01]
Approved by: so (cperciva)
Approved by: re (kensmith)
Security: FreeBSD-SA-09:06.ktimer
Errata: FreeBSD-EN-09:01.kenv
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/kern_environment.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_time.c | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c index a5658ca..038515b 100644 --- a/sys/kern/kern_environment.c +++ b/sys/kern/kern_environment.c @@ -87,7 +87,7 @@ kenv(td, uap) } */ *uap; { char *name, *value, *buffer = NULL; - size_t len, done, needed; + size_t len, done, needed, buflen; int error, i; KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0")); @@ -100,13 +100,17 @@ kenv(td, uap) return (error); #endif done = needed = 0; + buflen = uap->len; + if (buflen > KENV_SIZE * (KENV_MNAMELEN + KENV_MVALLEN + 2)) + buflen = KENV_SIZE * (KENV_MNAMELEN + + KENV_MVALLEN + 2); if (uap->len > 0 && uap->value != NULL) - buffer = malloc(uap->len, M_TEMP, M_WAITOK|M_ZERO); + buffer = malloc(buflen, M_TEMP, M_WAITOK|M_ZERO); mtx_lock(&kenv_lock); for (i = 0; kenvp[i] != NULL; i++) { len = strlen(kenvp[i]) + 1; needed += len; - len = min(len, uap->len - done); + len = min(len, buflen - done); /* * If called with a NULL or insufficiently large * buffer, just keep computing the required size. diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index a8ecace..99c1a53 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1085,7 +1085,8 @@ itimer_find(struct proc *p, int timerid) struct itimer *it; PROC_LOCK_ASSERT(p, MA_OWNED); - if ((p->p_itimers == NULL) || (timerid >= TIMER_MAX) || + if ((p->p_itimers == NULL) || + (timerid < 0) || (timerid >= TIMER_MAX) || (it = p->p_itimers->its_timers[timerid]) == NULL) { return (NULL); } |