Skip to content

Commit

Permalink
perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet
Browse files Browse the repository at this point in the history
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 <[email protected]>
Suggested-by: Robert Walker <[email protected]>
Signed-off-by: Leo Yan <[email protected]>
Tested-by: Robert Walker <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mathieu Poirier <[email protected]>
Cc: Mike Leach <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Suzuki K Poulouse <[email protected]>
Cc: [email protected]
Fixes: 7100b12 ("perf cs-etm: Generate branch sample for exception packet")
Fixes: 24fff5e ("perf cs-etm: Avoid stale branch samples when flush packet")
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Leo Yan authored and acmel committed May 2, 2019
1 parent cf0c37b commit 35bb59c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tools/perf/util/cs-etm.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,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);
Expand Down

0 comments on commit 35bb59c

Please sign in to comment.