Skip to contentSkip to conversation

perf callchain: Fix segfault in thread__resolve_callchain_sample()

PATCH Applied Adrian Hunter 3 participants 3 messages Nov 14, 2019 – Nov 19, 2019 perf events

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

PATCH 1/1 perf callchain: Fix segfault in thread__resolve_callchain_sample()

Do not dereference 'chain' when it is NULL.

  $ perf record -e intel_pt//u -e branch-misses:u uname
  $ perf report --itrace=l --branch-history
  perf: Segmentation fault
Fixes e9024d519d89 ("perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc}")
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 6a0f5c25ce3e..0a21ab69a247 100644
@@ -2414,7 +2414,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 	}
 
 check_calls:
-	if (callchain_param.order != ORDER_CALLEE) {
+	if (chain && callchain_param.order != ORDER_CALLEE) {
 		err = find_prev_cpumode(chain, thread, cursor, parent, root_al,
 					&cpumode, chain->nr - first_call);
 		if (err)
Signature · 1 line
2.17.1
#1 lore raw

Em Thu, Nov 14, 2019 at 04:25:38PM +0200, Adrian Hunter escreveu:

Quoted 5 lines

Do not dereference 'chain' when it is NULL.

  $ perf record -e intel_pt//u -e branch-misses:u uname
  $ perf report --itrace=l --branch-history
  perf: Segmentation fault

Thanks, tested and applied.

- Arnaldo

Quoted 21 lines
Fixes e9024d519d89 ("perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc}")
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 6a0f5c25ce3e..0a21ab69a247 100644
@@ -2414,7 +2414,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 	}
 
 check_calls:
-	if (callchain_param.order != ORDER_CALLEE) {
+	if (chain && callchain_param.order != ORDER_CALLEE) {
 		err = find_prev_cpumode(chain, thread, cursor, parent, root_al,
 					&cpumode, chain->nr - first_call);
 		if (err)
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
merge bot Applied
#2 lore raw
In reply to Adrian Hunter
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     aceb98261ea7d9fe38f9c140c5531f0b13623832
Gitweb:        https://git.kernel.org/tip/aceb98261ea7d9fe38f9c140c5531f0b13623832
Author:        Adrian Hunter <[email protected]>
AuthorDate:    Thu, 14 Nov 2019 16:25:38 +02:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Mon, 18 Nov 2019 13:01:59 -03:00

perf callchain: Fix segfault in thread__resolve_callchain_sample()

Do not dereference 'chain' when it is NULL.

  $ perf record -e intel_pt//u -e branch-misses:u uname
  $ perf report --itrace=l --branch-history
  perf: Segmentation fault
Fixes e9024d519d89 ("perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc}")
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/machine.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/machine.c +1 -1
index 7d2e211..71ee078 100644
@@ -2385,7 +2385,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 	}
 
 check_calls:
-	if (callchain_param.order != ORDER_CALLEE) {
+	if (chain && callchain_param.order != ORDER_CALLEE) {
 		err = find_prev_cpumode(chain, thread, cursor, parent, root_al,
 					&cpumode, chain->nr - first_call);
 		if (err)