diff options
authorLeo Yan <>2019-04-28 16:32:27 +0800
committerGreg Kroah-Hartman <>2019-05-25 18:22:30 +0200
commit58d1e074c74287b9f92e8ef357372e6189ccf0a7 (patch)
parentcd448c27b08eabae019f7d933f6313768617ad0d (diff)
perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet
[ Upstream commit 35bb59c10a6d0578806dd500477dae9cb4be344e ] Robert Walker reported a segmentation fault is observed when process CoreSight trace data; this issue can be easily reproduced by the command 'perf report --itrace=i1000i' for decoding tracing data. If neither the 'b' flag (synthesize branches events) nor 'l' flag (synthesize last branch entries) are specified to option '--itrace', cs_etm_queue::prev_packet will not been initialised. After merging the code to support exception packets and sample flags, there introduced a number of uses of cs_etm_queue::prev_packet without checking whether it is valid, for these cases any accessing to uninitialised prev_packet will cause crash. As cs_etm_queue::prev_packet is used more widely now and it's already hard to follow which functions have been called in a context where the validity of cs_etm_queue::prev_packet has been checked, this patch always allocates memory for cs_etm_queue::prev_packet. Reported-by: Robert Walker <> Suggested-by: Robert Walker <> Signed-off-by: Leo Yan <> Tested-by: Robert Walker <> Cc: Alexander Shishkin <> Cc: Jiri Olsa <> Cc: Mathieu Poirier <> Cc: Mike Leach <> Cc: Namhyung Kim <> Cc: Suzuki K Poulouse <> Cc: Fixes: 7100b12cf474 ("perf cs-etm: Generate branch sample for exception packet") Fixes: 24fff5eb2b93 ("perf cs-etm: Avoid stale branch samples when flush packet") Link: Signed-off-by: Arnaldo Carvalho de Melo <> Signed-off-by: Sasha Levin <>
1 files changed, 3 insertions, 5 deletions
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 27a374ddf661..947f1bb2fbdf 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -345,11 +345,9 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
if (!etmq->packet)
goto out_free;
- if (etm->synth_opts.last_branch || etm->sample_branches) {
- etmq->prev_packet = zalloc(szp);
- if (!etmq->prev_packet)
- goto out_free;
- }
+ etmq->prev_packet = zalloc(szp);
+ if (!etmq->prev_packet)
+ goto out_free;
if (etm->synth_opts.last_branch) {
size_t sz = sizeof(struct branch_stack);