Skip to contentSkip to conversation

trace-cmd: Don't SIGSEGV when event field format cannot be parsed.

PATCH In review David Daney 2 participants 4 messages Jul 13, 2010 – Jul 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace-cmd: Don't SIGSEGV when event field format cannot be parsed.

Quoted 1 line

From the MIPS kernel we get things like:

print fmt: "page=%p pfn=%lu order=%d migratetype=%d", REC->page, ({ struct page *__pg = (REC->page); int __sec = page_to_section(__pg); (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); }), REC->order, REC->migratetype

This cannot be parsed, leading to a NULL struct event_format* being passed to pevent_get_common_field_val, which produces a SIGSEGV. It would be good to get a parsable format from the kernel, but to remediate the problem for legacy kernels, we can just return an error indicator in this case. This allows some output from trace-cmd report, although perhaps with some missing data. But this is better than crashing.

---
 parse-events.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
parse-events.c +3 -0
index 9d5a3fa..16fff12 100644
@@ -4481,6 +4481,9 @@ int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
 {
 	struct format_field *field;
 
+	if (!event)
+		return -1;
+
 	field = pevent_find_common_field(event, name);
 
 	return get_field_val(s, field, name, record, val, err);
Signature · 1 line
1.6.6.1
#1 lore raw
Quoted 22 lines · David Daney
Quoted 1 line

From the MIPS kernel we get things like:

print fmt: "page=%p pfn=%lu order=%d migratetype=%d", REC->page, ({ struct page *__pg = (REC->page); int __sec = page_to_section(__pg); (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); }), REC->order, REC->migratetype

This cannot be parsed, leading to a NULL struct event_format* being passed to pevent_get_common_field_val, which produces a SIGSEGV. It would be good to get a parsable format from the kernel, but to remediate the problem for legacy kernels, we can just return an error indicator in this case. This allows some output from trace-cmd report, although perhaps with some missing data. But this is better than crashing.

---
 parse-events.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
parse-events.c +0 -0
index 9d5a3fa..16fff12 100644

parse-events.c int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event, · line 4481

Quoted 1 line
parse-events.c +0 -0
@@ -4481,6 +4481,9 @@ int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
 {

To be consistent, probably all the pevent_get_*field* should test for null event.

Did you want to resend a patch that does that?

-- Steve

Quoted 8 lines
parse-events.c +3 -0
 	struct format_field *field;
 
+	if (!event)
+		return -1;
+
 	field = pevent_find_common_field(event, name);
 
 	return get_field_val(s, field, name, record, val, err);
#2 lore raw

PATCH 1/1 trace-cmd: Don't SIGSEGV when event field format cannot be parsed (v2).

Quoted 1 line

From the MIPS kernel we get things like:

print fmt: "page=%p pfn=%lu order=%d migratetype=%d", REC->page, ({ struct page *__pg = (REC->page); int __sec = page_to_section(__pg); (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); }), REC->order, REC->migratetype

This cannot be parsed, leading to a NULL struct event_format* being passed to pevent_get_common_field_val, which produces a SIGSEGV. It would be good to get a parsable format from the kernel, but to remediate the problem for legacy kernels, we can just return an error indicator in this case. This allows some output from trace-cmd report, although perhaps with some missing data. But this is better than crashing.

(v2): Do the check in all pevent_get_*

---
 parse-events.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
parse-events.c +9 -0
index 1e854e2..595ba90 100644
@@ -4464,6 +4464,9 @@ int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
 {
 	struct format_field *field;
 
+	if (!event)
+		return -1;
+
 	field = pevent_find_field(event, name);
 
 	return get_field_val(s, field, name, record, val, err);
@@ -4486,6 +4489,9 @@ int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
 {
 	struct format_field *field;
 
+	if (!event)
+		return -1;
+
 	field = pevent_find_common_field(event, name);
 
 	return get_field_val(s, field, name, record, val, err);
@@ -4508,6 +4514,9 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
 {
 	struct format_field *field;
 
+	if (!event)
+		return -1;
+
 	field = pevent_find_any_field(event, name);
 
 	return get_field_val(s, field, name, record, val, err);
Signature · 1 line
1.7.1.1
#3 lore raw

Re: [PATCH] trace-cmd: Don't SIGSEGV when event field format cannot be parsed (v2).

Quoted 12 lines · David Daney
Quoted 1 line

From the MIPS kernel we get things like:

print fmt: "page=%p pfn=%lu order=%d migratetype=%d", REC->page, ({ struct page *__pg = (REC->page); int __sec = page_to_section(__pg); (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); }), REC->order, REC->migratetype

This cannot be parsed, leading to a NULL struct event_format* being passed to pevent_get_common_field_val, which produces a SIGSEGV. It would be good to get a parsable format from the kernel, but to remediate the problem for legacy kernels, we can just return an error indicator in this case. This allows some output from trace-cmd report, although perhaps with some missing data. But this is better than crashing.

Quoted 3 lines

(v2): Do the check in all pevent_get_*

Applied, thanks David!

-- Steve