perf cs-etm: Fix segfault in dso lookup
authorJames Clark <james.clark@arm.com>
Tue, 18 Apr 2023 14:12:03 +0000 (15:12 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 18 Apr 2023 15:25:10 +0000 (12:25 -0300)
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: 63df0e4bc368adbd ("perf map: Add accessor for dso")
Signed-off-by: James Clark <james.clark@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230418141203.673465-1-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/cs-etm.c

index 1038659..8dd81dd 100644 (file)
@@ -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 &&