From: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com>
To: Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@redhat.com>
Cc: linux-kernel@vger.kernel.org, kernel@openvz.org
Subject: [PATCH] tracing: fix va_list breakage in trace_check_vprintf()
Date: Wed, 17 Nov 2021 21:37:20 +0300 [thread overview]
Message-ID: <20211117183720.15573-1-nikita.yushchenko@virtuozzo.com> (raw)
When trace_check_vprintf() extracts parts of the format string and
passes those to trace_seq_printf() together with va_list, it expects
that trace_seq_printf() consumes arguments from va_list, as defined
by the passed format substring.
However, trace_seq_printf() has a special path for overflow handling,
that does not consume any arguments from va_list. This causes va_list
to get out of sync with format string processing, the next va_arg()
inside trace_check_vprintf() gets wrong argument, and WARN_ON_ONCE()
hits.
This situation easily triggers by ftrace_stress_test from LTP.
Fix that by adding a dummy vsnprintf() call to the overflow path inside
trace_seq_printf() to ensure args from va_list are still consumed.
Signed-off-by: Nikita Yushchenko <nikita.yushchenko@virtuozzo.com>
---
kernel/trace/trace_seq.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
index 9c90b3a7dce2..3551b5e18aa2 100644
--- a/kernel/trace/trace_seq.c
+++ b/kernel/trace/trace_seq.c
@@ -141,9 +141,15 @@ EXPORT_SYMBOL_GPL(trace_seq_bitmask);
void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
{
unsigned int save_len = s->seq.len;
+ char buf[1];
- if (s->full)
+ if (s->full) {
+ /* Consume args from va_list before returning, some callers
+ * expect that.
+ */
+ vsnprintf(buf, sizeof(buf), fmt, args);
return;
+ }
__trace_seq_init(s);
--
2.30.2
next reply other threads:[~2021-11-17 18:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 18:37 Nikita Yushchenko [this message]
2021-11-17 23:38 ` [PATCH] tracing: fix va_list breakage in trace_check_vprintf() Steven Rostedt
2021-11-17 23:41 ` Steven Rostedt
2021-11-18 4:57 ` Nikita Yushchenko
2021-11-18 5:44 ` [PATCH] trace: don't use out-of-sync va_list in event printing Nikita Yushchenko
2021-11-18 14:30 ` [PATCH] tracing: fix va_list breakage in trace_check_vprintf() Steven Rostedt
2021-11-18 14:54 ` Nikita Yushchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211117183720.15573-1-nikita.yushchenko@virtuozzo.com \
--to=nikita.yushchenko@virtuozzo.com \
--cc=kernel@openvz.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).