Date: Sun, 19 Mar 2017 15:56:06 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r315562 - in stable/10/sys: kern sys Message-ID: <201703191556.v2JFu6SU002650@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Sun Mar 19 15:56:06 2017 New Revision: 315562 URL: https://svnweb.freebsd.org/changeset/base/315562 Log: MFC r315155: Ktracing kevent(2) calls with unusual arguments might leads to an overly large allocation requests. PR: 217435 Modified: stable/10/sys/kern/kern_event.c stable/10/sys/kern/kern_ktrace.c stable/10/sys/sys/ktrace.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/kern/kern_event.c ============================================================================== --- stable/10/sys/kern/kern_event.c Sun Mar 19 15:53:17 2017 (r315561) +++ stable/10/sys/kern/kern_event.c Sun Mar 19 15:56:06 2017 (r315562) @@ -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 kev 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 kev #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 kev #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 Modified: stable/10/sys/kern/kern_ktrace.c ============================================================================== --- stable/10/sys/kern/kern_ktrace.c Sun Mar 19 15:53:17 2017 (r315561) +++ stable/10/sys/kern/kern_ktrace.c Sun Mar 19 15:56:06 2017 (r315562) @@ -132,7 +132,7 @@ static SYSCTL_NODE(_kern, OID_AUTO, ktra 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"); Modified: stable/10/sys/sys/ktrace.h ============================================================================== --- stable/10/sys/sys/ktrace.h Sun Mar 19 15:53:17 2017 (r315561) +++ stable/10/sys/sys/ktrace.h Sun Mar 19 15:56:06 2017 (r315562) @@ -276,7 +276,7 @@ void ktrcapfail(enum ktr_cap_fail_type, 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>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703191556.v2JFu6SU002650>