Skip to contentSkip to conversation

perf data convert: Fix segfault when converting to json when cpu_desc isn't set

PATCH Applied Ilkka Koskinen 3 participants 3 messages Feb 23, 2024 – Feb 27, 2024 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 perf data convert: Fix segfault when converting to json when cpu_desc isn't set

Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get assigned.

Running

	$ perf data convert --to-json perf.data.json

ends up calling output_json_string() with NULL pointer, which causes a segmentation fault.

---

v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Changed the patch based on James's comments.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
- https://lore.kernel.org/all/[email protected]/
v4:
- Made the fix more generic in case there are other architectures where cpu_desc isn't assigned as asked by Namhyung
- Rephrased the subject line
---

tools/perf/util/data-convert-json.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +3 -1
index 5bb3c2ba95ca..09d57efd2d9d 100644
@@ -284,7 +284,9 @@ static void output_headers(struct perf_session *session, struct convert_json *c)
 	output_json_key_string(out, true, 2, "os-release", header->env.os_release);
 	output_json_key_string(out, true, 2, "arch", header->env.arch);
 
-	output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+	if (header->env.cpu_desc)
+		output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+
 	output_json_key_string(out, true, 2, "cpuid", header->env.cpuid);
 	output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online);
 	output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail);
Signature · 1 line
2.43.0
maintainer Acked-by on v4 1/1
#1 lore raw
Quoted 10 lines · Ilkka Koskinen

Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get assigned.

Running

	$ perf data convert --to-json perf.data.json

ends up calling output_json_string() with NULL pointer, which causes a segmentation fault.

- Arnaldo

Quoted 36 lines

---

v1:
- https://lore.kernel.org/all/[email protected]/
v2:
- Changed the patch based on James's comments.
v3:
- The architecture is checked from the actual data file to allow one to do conversion on another system. (thanks to James for the feedback)
- https://lore.kernel.org/all/[email protected]/
v4:
- Made the fix more generic in case there are other architectures where cpu_desc isn't assigned as asked by Namhyung
- Rephrased the subject line
---

tools/perf/util/data-convert-json.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/data-convert-json.c +3 -1
index 5bb3c2ba95ca..09d57efd2d9d 100644
@@ -284,7 +284,9 @@ static void output_headers(struct perf_session *session, struct convert_json *c)
 	output_json_key_string(out, true, 2, "os-release", header->env.os_release);
 	output_json_key_string(out, true, 2, "arch", header->env.arch);
 
-	output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+	if (header->env.cpu_desc)
+		output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc);
+
 	output_json_key_string(out, true, 2, "cpuid", header->env.cpuid);
 	output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online);
 	output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail);
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw
In reply to Ilkka Koskinen
Quoted 10 lines · Ilkka Koskinen

Arm64 doesn't have Model in /proc/cpuinfo and, thus, cpu_desc doesn't get assigned.

Running

	$ perf data convert --to-json perf.data.json

ends up calling output_json_string() with NULL pointer, which causes a segmentation fault.

[...]

Applied to perf-tools-next, thanks!

Best regards,

Signature · 1 line
Namhyung Kim <[email protected]>