Date: Sun, 13 Jun 2021 01:45:03 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 66200d321826 - stable/13 - ktrace: use the limit of the trace initiator for file size limit on writes Message-ID: <202106130145.15D1j3rh051880@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=66200d32182612b90e3602877ff9a2deb867b252 commit 66200d32182612b90e3602877ff9a2deb867b252 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-05-14 23:51:01 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-06-13 01:22:33 +0000 ktrace: use the limit of the trace initiator for file size limit on writes (cherry picked from commit 02645b886bc62dfd8a998fd51d2e6c1bbca03ecb) --- sys/kern/kern_ktrace.c | 6 ++++++ sys/kern/vfs_vnops.c | 18 ++++++++++-------- sys/sys/proc.h | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index c923149ed129..d44f6b9ab994 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$"); #include <sys/namei.h> #include <sys/priv.h> #include <sys/proc.h> +#include <sys/resourcevar.h> #include <sys/unistd.h> #include <sys/vnode.h> #include <sys/socket.h> @@ -148,6 +149,7 @@ static struct sx ktrace_sx; struct ktr_io_params { struct vnode *vp; struct ucred *cr; + off_t lim; u_int refs; }; @@ -465,6 +467,7 @@ ktr_io_params_alloc(struct thread *td, struct vnode *vp) res = malloc(sizeof(struct ktr_io_params), M_KTRACE, M_WAITOK); res->vp = vp; res->cr = crhold(td->td_ucred); + res->lim = lim_cur(td, RLIMIT_FSIZE); res->refs = 1; return (res); } @@ -1257,6 +1260,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) struct uio auio; struct iovec aiov[3]; struct mount *mp; + off_t lim; int datalen, buflen; int error; @@ -1284,6 +1288,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) vp = kiop->vp; cred = kiop->cr; + lim = kiop->lim; vrefact(vp); KASSERT(cred != NULL, ("ktr_writerequest: cred == NULL")); @@ -1321,6 +1326,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + td->td_ktr_io_lim = lim; #ifdef MAC error = mac_vnode_check_write(cred, NOCRED, vp); if (error == 0) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 8be30df40dc5..fb94b1470a2d 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -2360,18 +2360,20 @@ int vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio, struct thread *td) { + off_t lim; if (vp->v_type != VREG || td == NULL || (td->td_pflags2 & TDP2_ACCT) != 0) return (0); - if ((uoff_t)uio->uio_offset + uio->uio_resid > - lim_cur(td, RLIMIT_FSIZE)) { - PROC_LOCK(td->td_proc); - kern_psignal(td->td_proc, SIGXFSZ); - PROC_UNLOCK(td->td_proc); - return (EFBIG); - } - return (0); + ktr_write = (td->td_pflags & TDP_INKTRACE) != 0; + lim = ktr_write ? td->td_ktr_io_lim : lim_cur(td, RLIMIT_FSIZE); + if ((uoff_t)uio->uio_offset + uio->uio_resid < lim) + return (0); + + PROC_LOCK(td->td_proc); + kern_psignal(td->td_proc, SIGXFSZ); + PROC_UNLOCK(td->td_proc); + return (EFBIG); } int diff --git a/sys/sys/proc.h b/sys/sys/proc.h index fb5714818163..d4476ac8d410 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -377,6 +377,7 @@ struct thread { void *td_lkpi_task; /* LinuxKPI task struct pointer */ int td_pmcpend; void *td_coredump; /* (c) coredump request. */ + off_t td_ktr_io_lim; /* (k) limit for ktrace file size */ #ifdef EPOCH_TRACE SLIST_HEAD(, epoch_tracker) td_epochs; #endif
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202106130145.15D1j3rh051880>