linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Zanussi <zanussi@kernel.org>
To: rostedt@goodmis.org, axelrasmussen@google.com
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 6/7] tracing: Handle synthetic event array field type checking correctly
Date: Mon, 12 Oct 2020 15:18:08 -0500	[thread overview]
Message-ID: <65a8c7dc784df121ea4b1c0060124e218f2162d0.1602533267.git.zanussi@kernel.org> (raw)
In-Reply-To: <cover.1602533267.git.zanussi@kernel.org>
In-Reply-To: <cover.1602533267.git.zanussi@kernel.org>

Since synthetic event array types are derived from the field name,
there may be a semicolon at the end of the type which should be
stripped off.

If there are more characters following that, normal type string
checking will result in an invalid type.

Without this patch, you can end up with an invalid field type string
that gets displayed in both the synthetic event description and the
event format:

Before:

  # echo 'myevent char str[16]; int v' >> synthetic_events
  # cat synthetic_events
    myevent	char[16]; str; int v

  name: myevent
  ID: 1936
  format:
  	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
  	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
  	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
  	field:int common_pid;	offset:4;	size:4;	signed:1;

  	field:char str[16];;	offset:8;	size:16;	signed:1;
  	field:int v;	offset:40;	size:4;	signed:1;

  print fmt: "str=%s, v=%d", REC->str, REC->v

After:

  # echo 'myevent char str[16]; int v' >> synthetic_events
  # cat synthetic_events
    myevent	char[16] str; int v

  # cat events/synthetic/myevent/format
  name: myevent
  ID: 1936
  format:
	field:unsigned short common_type;	offset:0;	size:2;	signed:0;
	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;
	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;
	field:int common_pid;	offset:4;	size:4;	signed:1;

	field:char str[16];	offset:8;	size:16;	signed:1;
	field:int v;	offset:40;	size:4;	signed:1;

  print fmt: "str=%s, v=%d", REC->str, REC->v

Fixes: 4b147936fa50 (tracing: Add support for 'synthetic' events)
Reported-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
---
 kernel/trace/trace_events_synth.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index 64c65be62dfe..5c3f5ae6f0bd 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -179,7 +179,7 @@ static int synth_field_string_size(char *type)
 	start += sizeof("char[") - 1;
 
 	end = strchr(type, ']');
-	if (!end || end < start)
+	if (!end || end < start || type + strlen(type) > end + 1)
 		return -EINVAL;
 
 	len = end - start;
@@ -630,8 +630,11 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
 	if (field_type[0] == ';')
 		field_type++;
 	len = strlen(field_type) + 1;
-	if (array)
+	if (array) {
 		len += strlen(array);
+		if (array[strlen(array) - 1] == ';')
+			len--;
+	}
 	if (prefix)
 		len += strlen(prefix);
 
-- 
2.17.1


  parent reply	other threads:[~2020-10-12 20:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 20:18 [PATCH v2 0/7] tracing: Synthetic event dynamic string fixes Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 1/7] tracing: Don't show dynamic string internals in synthetic event description Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 2/7] tracing: Move is_good_name() from trace_probe.h to trace.h Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 3/7] tracing: Check that the synthetic event and field names are legal Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 4/7] tracing: Add synthetic event error logging Tom Zanussi
2020-10-12 21:42   ` Steven Rostedt
2020-10-12 21:49     ` Steven Rostedt
2020-10-12 21:59       ` Tom Zanussi
2020-10-12 22:04   ` Steven Rostedt
2020-10-12 22:24     ` Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 5/7] selftests/ftrace: Change synthetic event name for inter-event-combined test Tom Zanussi
2020-10-12 20:18 ` Tom Zanussi [this message]
2020-10-12 22:14   ` [PATCH v2 6/7] tracing: Handle synthetic event array field type checking correctly Steven Rostedt
2020-10-12 22:24     ` Tom Zanussi
2020-10-12 20:18 ` [PATCH v2 7/7] selftests/ftrace: Add test case for synthetic event syntax errors Tom Zanussi

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=65a8c7dc784df121ea4b1c0060124e218f2162d0.1602533267.git.zanussi@kernel.org \
    --to=zanussi@kernel.org \
    --cc=axelrasmussen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --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).