Skip to content

Commit 095fe48

Browse files
committed
tracing: Limit trace_marker writes to just 4K
Limit the max print event of trace_marker to just 4K string size. This must also be less than the amount that can be held by a trace_seq along with the text that is before the output (like the task name, PID, CPU, state, etc). As trace_seq is made to handle large events (some greater than 4K). Make the max size of a trace_marker write event be 4K which is guaranteed to fit in the trace_seq buffer. Link: https://lore.kernel.org/linux-trace-kernel/20240304223433.4ba47dff@gandalf.local.home Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 6f42249 commit 095fe48

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/trace/trace.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7293,6 +7293,8 @@ tracing_free_buffer_release(struct inode *inode, struct file *filp)
72937293
return 0;
72947294
}
72957295

7296+
#define TRACE_MARKER_MAX_SIZE 4096
7297+
72967298
static ssize_t
72977299
tracing_mark_write(struct file *filp, const char __user *ubuf,
72987300
size_t cnt, loff_t *fpos)
@@ -7320,6 +7322,9 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
73207322
if ((ssize_t)cnt < 0)
73217323
return -EINVAL;
73227324

7325+
if (cnt > TRACE_MARKER_MAX_SIZE)
7326+
cnt = TRACE_MARKER_MAX_SIZE;
7327+
73237328
meta_size = sizeof(*entry) + 2; /* add '\0' and possible '\n' */
73247329
again:
73257330
size = cnt + meta_size;
@@ -7328,11 +7333,6 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
73287333
if (cnt < FAULTED_SIZE)
73297334
size += FAULTED_SIZE - cnt;
73307335

7331-
if (size > TRACE_SEQ_BUFFER_SIZE) {
7332-
cnt -= size - TRACE_SEQ_BUFFER_SIZE;
7333-
goto again;
7334-
}
7335-
73367336
buffer = tr->array_buffer.buffer;
73377337
event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,
73387338
tracing_gen_ctx());

0 commit comments

Comments
 (0)