linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf: cs-etm: Fix segfault in dso lookup
@ 2023-04-18 14:12 James Clark
  2023-04-18 15:26 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 2+ messages in thread
From: James Clark @ 2023-04-18 14:12 UTC (permalink / raw)
  To: linux-perf-users, acme
  Cc: James Clark, Mathieu Poirier, Suzuki K Poulose, Mike Leach,
	Leo Yan, John Garry, Will Deacon, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, coresight, linux-arm-kernel,
	linux-kernel

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")
Signed-off-by: James Clark <james.clark@arm.com>
---
 tools/perf/util/cs-etm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 103865968700..8dd81ddd9e4e 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -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 &&
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] perf: cs-etm: Fix segfault in dso lookup
  2023-04-18 14:12 [PATCH] perf: cs-etm: Fix segfault in dso lookup James Clark
@ 2023-04-18 15:26 ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2023-04-18 15:26 UTC (permalink / raw)
  To: James Clark
  Cc: linux-perf-users, Mathieu Poirier, Suzuki K Poulose, Mike Leach,
	Leo Yan, John Garry, Will Deacon, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Ian Rogers, Adrian Hunter, coresight, linux-arm-kernel,
	linux-kernel

Em Tue, Apr 18, 2023 at 03:12:03PM +0100, James Clark escreveu:
> 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

> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>  tools/perf/util/cs-etm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> index 103865968700..8dd81ddd9e4e 100644
> --- a/tools/perf/util/cs-etm.c
> +++ b/tools/perf/util/cs-etm.c
> @@ -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 &&
> -- 
> 2.34.1
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-18 15:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-18 14:12 [PATCH] perf: cs-etm: Fix segfault in dso lookup James Clark
2023-04-18 15:26 ` Arnaldo Carvalho de Melo

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).