[Devel] [PATCH RHEL9 COMMIT] ms/tracing: Don't use out-of-sync va_list in event printing

Konstantin Khorenko khorenko at virtuozzo.com
Mon Dec 6 19:30:45 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.32
------>
commit f9c3066fa27352161cd6c4c356e228689718b8e0
Author: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
Date:   Mon Dec 6 19:30:45 2021 +0300

    ms/tracing: Don't use out-of-sync va_list in event printing
    
    If trace_seq becomes full, trace_seq_vprintf() no longer consumes
    arguments from va_list, making va_list out of sync with format
    processing by trace_check_vprintf().
    
    This causes va_arg() in trace_check_vprintf() to return wrong
    positional argument, which results into a WARN_ON_ONCE() hit.
    
    ftrace_stress_test from LTP triggers this situation.
    
    Fix it by explicitly avoiding further use if va_list at the point
    when it's consistency can no longer be guaranteed.
    
    Link: https://lkml.kernel.org/r/20211118145516.13219-1-nikita.yushchenko@virtuozzo.com
    
    Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
    
    Signed-off-by: Steven Rostedt (VMware) <rostedt at goodmis.org>
    
    ms commit: 2ef75e9bd2c9 ("tracing: Don't use out-of-sync va_list in event
    printing")
    
    https://jira.sw.ru/browse/PSBM-135327
    Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 kernel/trace/trace.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a1adb29ef5c1..3f527c2e08f2 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3826,6 +3826,18 @@ void trace_check_vprintf(struct trace_iterator *iter, const char *fmt,
 		iter->fmt[i] = '\0';
 		trace_seq_vprintf(&iter->seq, iter->fmt, ap);
 
+		/*
+		 * If iter->seq is full, the above call no longer guarantees
+		 * that ap is in sync with fmt processing, and further calls
+		 * to va_arg() can return wrong positional arguments.
+		 *
+		 * Ensure that ap is no longer used in this case.
+		 */
+		if (iter->seq.full) {
+			p = "";
+			break;
+		}
+
 		if (star)
 			len = va_arg(ap, int);
 


More information about the Devel mailing list