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>

Changed files
+5 -5
kernel
trace
+5 -5
kernel/trace/trace.c
··· 7293 7293 return 0; 7294 7294 } 7295 7295 7296 + #define TRACE_MARKER_MAX_SIZE 4096 7297 + 7296 7298 static ssize_t 7297 7299 tracing_mark_write(struct file *filp, const char __user *ubuf, 7298 7300 size_t cnt, loff_t *fpos) ··· 7322 7320 if ((ssize_t)cnt < 0) 7323 7321 return -EINVAL; 7324 7322 7323 + if (cnt > TRACE_MARKER_MAX_SIZE) 7324 + cnt = TRACE_MARKER_MAX_SIZE; 7325 + 7325 7326 meta_size = sizeof(*entry) + 2; /* add '\0' and possible '\n' */ 7326 7327 again: 7327 7328 size = cnt + meta_size; ··· 7332 7327 /* If less than "<faulted>", then make sure we can still add that */ 7333 7328 if (cnt < FAULTED_SIZE) 7334 7329 size += FAULTED_SIZE - cnt; 7335 - 7336 - if (size > TRACE_SEQ_BUFFER_SIZE) { 7337 - cnt -= size - TRACE_SEQ_BUFFER_SIZE; 7338 - goto again; 7339 - } 7340 7330 7341 7331 buffer = tr->array_buffer.buffer; 7342 7332 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, size,