Date: Sat, 22 May 2021 12:16:58 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: ea2b64c24133 - main - ktrace: add a kern.ktrace.filesize_limit_signal knob Message-ID: <202105221216.14MCGw20011808@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=ea2b64c2413355ac0d5fc6ff597342e9437a34d4 commit ea2b64c2413355ac0d5fc6ff597342e9437a34d4 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-05-18 16:05:39 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-05-22 12:16:09 +0000 ktrace: add a kern.ktrace.filesize_limit_signal knob When enabled, writes to ktrace.out that exceed the max file size limit cause SIGXFSZ as it should be, but note that the limit is taken from the process that initiated ktrace. When disabled, write is blocked, but signal is not send. Note that in either case ktrace for the affected process is stopped. Requested and reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D30257 --- sys/kern/kern_ktrace.c | 10 ++++++++++ sys/kern/vfs_vnops.c | 10 +++++++--- sys/sys/ktrace.h | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index b686f2e2717a..8783600df6b1 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -142,6 +142,16 @@ u_int ktr_geniosize = PAGE_SIZE; SYSCTL_UINT(_kern_ktrace, OID_AUTO, genio_size, CTLFLAG_RWTUN, &ktr_geniosize, 0, "Maximum size of genio event payload"); +/* + * Allow to not to send signal to traced process, in which context the + * ktr record is written. The limit is applied from the process that + * set up ktrace, so killing the traced process is not completely fair. + */ +int ktr_filesize_limit_signal = 0; +SYSCTL_INT(_kern_ktrace, OID_AUTO, filesize_limit_signal, CTLFLAG_RWTUN, + &ktr_filesize_limit_signal, 0, + "Send SIGXFSZ to the traced process when the log size limit is exceeded"); + static int print_message = 1; static struct mtx ktrace_mtx; static struct sx ktrace_sx; diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 9c309c83f805..9e45d1820eec 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -79,6 +79,7 @@ __FBSDID("$FreeBSD$"); #include <sys/syslog.h> #include <sys/unistd.h> #include <sys/user.h> +#include <sys/ktrace.h> #include <security/audit/audit.h> #include <security/mac/mac_framework.h> @@ -2360,6 +2361,7 @@ vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio, struct thread *td) { off_t lim; + bool ktr_write; if (vp->v_type != VREG || td == NULL || (td->td_pflags2 & TDP2_ACCT) != 0) @@ -2369,9 +2371,11 @@ vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio, 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); + if (!ktr_write || ktr_filesize_limit_signal) { + PROC_LOCK(td->td_proc); + kern_psignal(td->td_proc, SIGXFSZ); + PROC_UNLOCK(td->td_proc); + } return (EFBIG); } diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index c4ab985722c0..50030d002f97 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -299,6 +299,7 @@ void ktrcapfail(enum ktr_cap_fail_type, const cap_rights_t *, #define ktrstat_error(s, error) \ ktrstruct_error("stat", (s), sizeof(struct stat), error) extern u_int ktr_geniosize; +extern int ktr_filesize_limit_signal; #else #include <sys/cdefs.h>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105221216.14MCGw20011808>