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

Steven Rostedt rostedt at goodmis.org
Wed Feb 28 04:08:42 AEDT 2024


On Tue, 27 Feb 2024 11:56:14 -0500
Steven Rostedt <rostedt at goodmis.org> wrote:

> On Tue, 27 Feb 2024 22:08:18 +0530
> Sachin Sant <sachinp at linux.ibm.com> wrote:
> 
> > > 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;



More information about the Linuxppc-dev mailing list