aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-05-18 16:05:39 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-05-22 12:16:09 +0000
commitea2b64c2413355ac0d5fc6ff597342e9437a34d4 (patch)
tree1d24baf39dc16e51d48e44ec365c881e37b77528
parent02645b886bc62dfd8a998fd51d2e6c1bbca03ecb (diff)
downloadsrc-ea2b64c2413355ac0d5fc6ff597342e9437a34d4.tar.gz
src-ea2b64c2413355ac0d5fc6ff597342e9437a34d4.zip
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
-rw-r--r--sys/kern/kern_ktrace.c10
-rw-r--r--sys/kern/vfs_vnops.c10
-rw-r--r--sys/sys/ktrace.h1
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>