Re: [PATCH] perf machine: Fix NULL deref in thread__resolve_callchain_sample()
From: hu.shengming
Date: Tue Oct 27 2026 - 12:10:25 EST
lv.yating@xxxxxxxxxx wrote:
> From: lvyating <lv.yating@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
LGTM!
Reviewed-by: Shengming Hu <hu.shengming@xxxxxxxxxx>
--
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