diff options
author | kib <kib@FreeBSD.org> | 2017-03-19 15:56:06 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2017-03-19 15:56:06 +0000 |
commit | 367bb71c483cf7a7a70ce941e0a5fa2e929d38f2 (patch) | |
tree | a40f0bf6c6d82a47f5e57765d728933cd5b54156 | |
parent | b99ef16b54afe13145b759e50409e47854084552 (diff) | |
download | FreeBSD-src-367bb71c483cf7a7a70ce941e0a5fa2e929d38f2.zip FreeBSD-src-367bb71c483cf7a7a70ce941e0a5fa2e929d38f2.tar.gz |
MFC r315155:
Ktracing kevent(2) calls with unusual arguments might leads to an
overly large allocation requests.
PR: 217435
-rw-r--r-- | sys/kern/kern_event.c | 18 | ||||
-rw-r--r-- | sys/kern/kern_ktrace.c | 2 | ||||
-rw-r--r-- | sys/sys/ktrace.h | 2 |
3 files changed, 17 insertions, 5 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index 2c99803..45f8e48 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -825,6 +825,15 @@ done2: return (error); } +static size_t +kev_iovlen(int n, u_int kgio) +{ + + if (n < 0 || n >= kgio / sizeof(struct kevent)) + return (kgio); + return (n * sizeof(struct kevent)); +} + #ifndef _SYS_SYSPROTO_H_ struct kevent_args { int fd; @@ -848,6 +857,7 @@ sys_kevent(struct thread *td, struct kevent_args *uap) struct iovec ktriov; struct uio *ktruioin = NULL; struct uio *ktruioout = NULL; + u_int kgio; #endif if (uap->timeout != NULL) { @@ -860,13 +870,15 @@ sys_kevent(struct thread *td, struct kevent_args *uap) #ifdef KTRACE if (KTRPOINT(td, KTR_GENIO)) { + kgio = ktr_geniosize; ktriov.iov_base = uap->changelist; - ktriov.iov_len = uap->nchanges * sizeof(struct kevent); + ktriov.iov_len = kev_iovlen(uap->nchanges, kgio); ktruio = (struct uio){ .uio_iov = &ktriov, .uio_iovcnt = 1, .uio_segflg = UIO_USERSPACE, .uio_rw = UIO_READ, .uio_td = td }; ktruioin = cloneuio(&ktruio); ktriov.iov_base = uap->eventlist; + ktriov.iov_len = kev_iovlen(uap->nevents, kgio); ktriov.iov_len = uap->nevents * sizeof(struct kevent); ktruioout = cloneuio(&ktruio); } @@ -877,9 +889,9 @@ sys_kevent(struct thread *td, struct kevent_args *uap) #ifdef KTRACE if (ktruioin != NULL) { - ktruioin->uio_resid = uap->nchanges * sizeof(struct kevent); + ktruioin->uio_resid = kev_iovlen(uap->nchanges, kgio); ktrgenio(uap->fd, UIO_WRITE, ktruioin, 0); - ktruioout->uio_resid = td->td_retval[0] * sizeof(struct kevent); + ktruioout->uio_resid = kev_iovlen(td->td_retval[0], kgio); ktrgenio(uap->fd, UIO_READ, ktruioout, error); } #endif diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index b74d48e..aec892f 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -132,7 +132,7 @@ static SYSCTL_NODE(_kern, OID_AUTO, ktrace, CTLFLAG_RD, 0, "KTRACE options"); static u_int ktr_requestpool = KTRACE_REQUEST_POOL; TUNABLE_INT("kern.ktrace.request_pool", &ktr_requestpool); -static u_int ktr_geniosize = PAGE_SIZE; +u_int ktr_geniosize = PAGE_SIZE; TUNABLE_INT("kern.ktrace.genio_size", &ktr_geniosize); SYSCTL_UINT(_kern_ktrace, OID_AUTO, genio_size, CTLFLAG_RW, &ktr_geniosize, 0, "Maximum size of genio event payload"); diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index e63a41a..9b5824b 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -276,7 +276,7 @@ void ktrcapfail(enum ktr_cap_fail_type, const cap_rights_t *, ktrstruct("sockaddr", (s), ((struct sockaddr *)(s))->sa_len) #define ktrstat(s) \ ktrstruct("stat", (s), sizeof(struct stat)) - +extern u_int ktr_geniosize; #else #include <sys/cdefs.h> |