Skip to content

Commit 033c80d

Browse files
rostedtgregkh
authored andcommitted
tracing/probes: Limit size of event probe to 3K
[ Upstream commit b2aa3b4 ] There currently isn't a max limit an event probe can be. One could make an event greater than PAGE_SIZE, which makes the event useless because if it's bigger than the max event that can be recorded into the ring buffer, then it will never be recorded. A event probe should never need to be greater than 3K, so make that the max size. As long as the max is less than the max that can be recorded onto the ring buffer, it should be fine. Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Fixes: 93ccae7 ("tracing/kprobes: Support basic types on dynamic events") Link: https://patch.msgid.link/20260428122302.706610ba@gandalf.local.home Signed-off-by: Steven Rostedt <rostedt@goodmis.org> [ adjusted context to place MAX_PROBE_EVENT_SIZE near MAX_STRING_SIZE and appended EVENT_TOO_BIG after NEED_STRING_TYPE ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f5ee467 commit 033c80d

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

kernel/trace/trace_probe.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,12 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size,
13661366
parg->offset = *size;
13671367
*size += parg->type->size * (parg->count ?: 1);
13681368

1369+
if (*size > MAX_PROBE_EVENT_SIZE) {
1370+
ret = -E2BIG;
1371+
trace_probe_log_err(ctx->offset, EVENT_TOO_BIG);
1372+
goto fail;
1373+
}
1374+
13691375
if (parg->count) {
13701376
len = strlen(parg->type->fmttype) + 6;
13711377
parg->fmt = kmalloc(len, GFP_KERNEL);

kernel/trace/trace_probe.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define MAX_ARG_NAME_LEN 32
3636
#define MAX_BTF_ARGS_LEN 128
3737
#define MAX_STRING_SIZE PATH_MAX
38+
#define MAX_PROBE_EVENT_SIZE 3072
3839

3940
/* Reserved field names */
4041
#define FIELD_STRING_IP "__probe_ip"
@@ -546,7 +547,8 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
546547
C(NO_BTF_FIELD, "This field is not found."), \
547548
C(BAD_BTF_TID, "Failed to get BTF type info."),\
548549
C(BAD_TYPE4STR, "This type does not fit for string."),\
549-
C(NEED_STRING_TYPE, "$comm and immediate-string only accepts string type"),
550+
C(NEED_STRING_TYPE, "$comm and immediate-string only accepts string type"),\
551+
C(EVENT_TOO_BIG, "Event too big (too many fields?)"),
550552

551553
#undef C
552554
#define C(a, b) TP_ERR_##a

0 commit comments

Comments
 (0)