* [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample()
@ 2026-10-27 11:47 lv.yating
2026-10-27 15:21 ` Ian Rogers
0 siblings, 1 reply; 4+ messages in thread
From: lv.yating @ 2026-10-27 11:47 UTC (permalink / raw)
To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark
Cc: linux-perf-users, linux-kernel, liu.qingtao2, he.yilin,
zhang.cheng35, ye.zhihao1, shen.lin1, dai.hualiang, stable,
hu.shengming
From: lvyating <lv.yating@zte.com.cn>
When recording with -j stack, resolve_lbr_callchain_sample() can
dereference a NULL 'chain' pointer while resolving the branch
stack.
$ perf record -j stack -e branches:u uname
perf: Segmentation fault
Fix it by checking 'chain' for NULL before dereferencing it.
Fixes: 29be60c93d2d ("perf build-id: Mark DSO in sample callchains")
Signed-off-by: lvyating <lv.yating@zte.com.cn>
Cc: stable@vger.kernel.org
---
tools/perf/util/machine.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index f86b3b7df742..10a88c070814 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2858,7 +2858,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
if (chain)
chain_nr = chain->nr;
- if (evsel__has_branch_callstack(evsel)) {
+ if (chain && evsel__has_branch_callstack(evsel)) {
struct perf_env *env = evsel__env(evsel);
err = resolve_lbr_callchain_sample(thread, cursor, sample, parent,
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample()
2026-10-27 11:47 [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample() lv.yating
@ 2026-10-27 15:21 ` Ian Rogers
2026-10-27 20:37 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 4+ messages in thread
From: Ian Rogers @ 2026-10-27 15:21 UTC (permalink / raw)
To: lv.yating
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, james.clark, linux-perf-users,
linux-kernel, liu.qingtao2, he.yilin, zhang.cheng35, ye.zhihao1,
shen.lin1, dai.hualiang, stable, hu.shengming
On Tue, Oct 27, 2026 at 4:54 AM <lv.yating@zte.com.cn> wrote:
>
> From: lvyating <lv.yating@zte.com.cn>
>
> When recording with -j stack, resolve_lbr_callchain_sample() can
> dereference a NULL 'chain' pointer while resolving the branch
> stack.
>
> $ perf record -j stack -e branches:u uname
> perf: Segmentation fault
>
> Fix it by checking 'chain' for NULL before dereferencing it.
>
> Fixes: 29be60c93d2d ("perf build-id: Mark DSO in sample callchains")
> Signed-off-by: lvyating <lv.yating@zte.com.cn>
> Cc: stable@vger.kernel.org
Tested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
I wonder - this failure points to a lack of test coverage. For LBR the
main coverage comes from:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/record_lbr.sh?h=perf-tools-next
Could you help expand the tests to avoid regressions?
Thanks,
Ian
> ---
> tools/perf/util/machine.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index f86b3b7df742..10a88c070814 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2858,7 +2858,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
> if (chain)
> chain_nr = chain->nr;
>
> - if (evsel__has_branch_callstack(evsel)) {
> + if (chain && evsel__has_branch_callstack(evsel)) {
> struct perf_env *env = evsel__env(evsel);
>
> err = resolve_lbr_callchain_sample(thread, cursor, sample, parent,
> --
> 2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample()
2026-10-27 15:21 ` Ian Rogers
@ 2026-10-27 20:37 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-10-27 20:37 UTC (permalink / raw)
To: Ian Rogers
Cc: lv.yating, peterz, mingo, namhyung, mark.rutland,
alexander.shishkin, jolsa, adrian.hunter, james.clark,
linux-perf-users, linux-kernel, liu.qingtao2, he.yilin,
zhang.cheng35, ye.zhihao1, shen.lin1, dai.hualiang, stable,
hu.shengming
On Tue, Oct 27, 2026 at 08:21:16AM -0700, Ian Rogers wrote:
> On Tue, Oct 27, 2026 at 4:54 AM <lv.yating@zte.com.cn> wrote:
> > When recording with -j stack, resolve_lbr_callchain_sample() can
> > dereference a NULL 'chain' pointer while resolving the branch
> > stack.
> > $ perf record -j stack -e branches:u uname
> > perf: Segmentation fault
> > Fix it by checking 'chain' for NULL before dereferencing it.
> > Fixes: 29be60c93d2d ("perf build-id: Mark DSO in sample callchains")
> > Signed-off-by: lvyating <lv.yating@zte.com.cn>
> > Cc: stable@vger.kernel.org
> Tested-by: Ian Rogers <irogers@google.com>
> Reviewed-by: Ian Rogers <irogers@google.com>
Thanks, applied for v7.4.
> I wonder - this failure points to a lack of test coverage. For LBR the
> main coverage comes from:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/record_lbr.sh?h=perf-tools-next
> Could you help expand the tests to avoid regressions?
That would be great indeed,
- Arnaldo
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <2026102719473296875zO7s1T904dguHCkN5vy@zte.com.cn>]
* Re: [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample()
[not found] <2026102719473296875zO7s1T904dguHCkN5vy@zte.com.cn>
@ 2026-10-27 15:51 ` hu.shengming
0 siblings, 0 replies; 4+ messages in thread
From: hu.shengming @ 2026-10-27 15:51 UTC (permalink / raw)
To: lv.yating
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark, linux-perf-users,
linux-kernel, liu.qingtao2, he.yilin, zhang.cheng35, ye.zhihao1,
shen.lin1, dai.hualiang, stable
lv.yating@zte.com.cn wrote:
> From: lvyating <lv.yating@zte.com.cn>
>
> When recording with -j stack, resolve_lbr_callchain_sample() can
> dereference a NULL 'chain' pointer while resolving the branch
> stack.
>
> $ perf record -j stack -e branches:u uname
> perf: Segmentation fault
>
> Fix it by checking 'chain' for NULL before dereferencing it.
>
> Fixes: 29be60c93d2d ("perf build-id: Mark DSO in sample callchains")
> Signed-off-by: lvyating <lv.yating@zte.com.cn>
> Cc: stable@vger.kernel.org
LGTM!
Reviewed-by: Shengming Hu <hu.shengming@zte.com.cn>
--
With Best Regards,
Shengming
> ---
> tools/perf/util/machine.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index f86b3b7df742..10a88c070814 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -2858,7 +2858,7 @@ static int thread__resolve_callchain_sample(struct thread *thread,
> if (chain)
> chain_nr = chain->nr;
>
> - if (evsel__has_branch_callstack(evsel)) {
> + if (chain && evsel__has_branch_callstack(evsel)) {
> struct perf_env *env = evsel__env(evsel);
>
> err = resolve_lbr_callchain_sample(thread, cursor, sample, parent,
> --
> 2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-27 20:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27 11:47 [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample() lv.yating
2026-10-27 15:21 ` Ian Rogers
2026-10-27 20:37 ` Arnaldo Carvalho de Melo
[not found] <2026102719473296875zO7s1T904dguHCkN5vy@zte.com.cn>
2026-10-27 15:51 ` hu.shengming
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®