Skip to contentSkip to conversation

perf: cs-etm: Fix segfault in dso lookup

PATCH Applied James Clark 2 participants 2 messages Apr 18, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: cs-etm: Fix segfault in dso lookup

map__dso() is called before thread__find_map() which always results in a null pointer dereference. Fix it by finding first, then checking if it exists.

Fixes 63df0e4bc368 ("perf map: Add accessor for dso")
---
 tools/perf/util/cs-etm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +4 -2
index 103865968700..8dd81ddd9e4e 100644
@@ -885,9 +885,11 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
 		thread = etmq->etm->unknown_thread;
 	}
 
-	dso = map__dso(al.map);
+	if (!thread__find_map(thread, cpumode, address, &al))
+		return 0;
 
-	if (!thread__find_map(thread, cpumode, address, &al) || !dso)
+	dso = map__dso(al.map);
+	if (!dso)
 		return 0;
 
 	if (dso->data.status == DSO_DATA_STATUS_ERROR &&
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw

Em Tue, Apr 18, 2023 at 03:12:03PM +0100, James Clark escreveu:

Quoted 5 lines

map__dso() is called before thread__find_map() which always results in a null pointer dereference. Fix it by finding first, then checking if it exists.

Fixes 63df0e4bc368 ("perf map: Add accessor for dso")

Thanks, applied, checking if another such pattern slipped by in that cset.

- Arnaldo

Quoted 26 lines
---
 tools/perf/util/cs-etm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/cs-etm.c +4 -2
index 103865968700..8dd81ddd9e4e 100644
@@ -885,9 +885,11 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id,
 		thread = etmq->etm->unknown_thread;
 	}
 
-	dso = map__dso(al.map);
+	if (!thread__find_map(thread, cpumode, address, &al))
+		return 0;
 
-	if (!thread__find_map(thread, cpumode, address, &al) || !dso)
+	dso = map__dso(al.map);
+	if (!dso)
 		return 0;
 
 	if (dso->data.status == DSO_DATA_STATUS_ERROR &&
Signature · 1 line
2.34.1
Signature · 1 line
- Arnaldo