Skip to content

Commit 10819e2

Browse files
Tom Zanussirostedt
authored andcommitted
tracing: Handle synthetic event array field type checking correctly
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 Link: https://lkml.kernel.org/r/6587663b56c2d45ab9d8c8472a2110713cdec97d.1602598160.git.zanussi@kernel.org [ <[email protected]>: wrote parse_synth_field() snippet. ] Fixes: 4b14793 (tracing: Add support for 'synthetic' events) Reported-by: Masami Hiramatsu <[email protected]> Tested-by: Masami Hiramatsu <[email protected]> Signed-off-by: Tom Zanussi <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 96378b2 commit 10819e2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

kernel/trace/trace_events_synth.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static int synth_field_string_size(char *type)
174174
start += sizeof("char[") - 1;
175175

176176
end = strchr(type, ']');
177-
if (!end || end < start)
177+
if (!end || end < start || type + strlen(type) > end + 1)
178178
return -EINVAL;
179179

180180
len = end - start;
@@ -625,8 +625,14 @@ static struct synth_field *parse_synth_field(int argc, const char **argv,
625625
if (field_type[0] == ';')
626626
field_type++;
627627
len = strlen(field_type) + 1;
628-
if (array)
629-
len += strlen(array);
628+
629+
if (array) {
630+
int l = strlen(array);
631+
632+
if (l && array[l - 1] == ';')
633+
l--;
634+
len += l;
635+
}
630636
if (prefix)
631637
len += strlen(prefix);
632638

0 commit comments

Comments
 (0)