Thread (10 messages) 10 messages, 2 authors, 2024-02-27

Re: Kernel WARNING at lib/vsprintf.c:2721 while running ftrace kernel selftests

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2024-02-27 17:07:13
Subsystem: the rest, tracing · Maintainers: Linus Torvalds, Steven Rostedt, Masami Hiramatsu

On Tue, 27 Feb 2024 11:56:14 -0500
Steven Rostedt [off-list ref] wrote:
On Tue, 27 Feb 2024 22:08:18 +0530
Sachin Sant [off-list ref] wrote:
quoted
quoted
Can you apply this, and see if it triggers and if it does, print the line
that has the max size?
    
With this I see following trace

[   61.327138] ------------[ cut here ]------------
[   61.327159] MAX OUT OF RANGE 63492  
Well I guess there you have it ;-)

vsprintf() doesn't like a precision of 63492!

I'll look to see what the best way to deal with this is.
Does this fix it?

-- Steve
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index ff0b0a999171..e0840b94f1a2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6882,7 +6882,9 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 /* Used in tracing_mark_raw_write() as well */
 #define FAULTED_STR "<faulted>"
 #define FAULTED_SIZE (sizeof(FAULTED_STR) - 1) /* '\0' is already accounted for */
-
+#ifndef SHORT_MAX
+#define SHORT_MAX	((1<<15) - 1)
+#endif
 	if (tracing_disabled)
 		return -EINVAL;
 
@@ -6900,6 +6902,16 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	if (cnt < FAULTED_SIZE)
 		size += FAULTED_SIZE - cnt;
 
+	/*
+	 * trace_print_print() uses vsprintf() to determine the size via
+	 * the precision format "%*.s" which can not be greater than
+	 * a signed short.
+	 */
+	if (size > SHORT_MAX) {
+		cnt -= size - SHORT_MAX;
+		goto again;
+	}
+
 	if (size > TRACE_SEQ_BUFFER_SIZE) {
 		cnt -= size - TRACE_SEQ_BUFFER_SIZE;
 		goto again;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help