]> www.infradead.org Git - nvme.git/commitdiff
perf tool: fix dereferencing NULL al->maps
authorCasey Chen <cachen@purestorage.com>
Mon, 22 Jul 2024 21:15:48 +0000 (15:15 -0600)
committerNamhyung Kim <namhyung@kernel.org>
Fri, 26 Jul 2024 18:12:16 +0000 (11:12 -0700)
With 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions"),
when cpumode is 3 (macro PERF_RECORD_MISC_HYPERVISOR),
thread__find_map() could return with al->maps being NULL.

The path below could add a callchain_cursor_node with NULL ms.maps.

add_callchain_ip()
  thread__find_symbol(.., &al)
    thread__find_map(.., &al)   // al->maps becomes NULL
  ms.maps = maps__get(al.maps)
  callchain_cursor_append(..., &ms, ...)
    node->ms.maps = maps__get(ms->maps)

Then the path below would dereference NULL maps and get segfault.

fill_callchain_info()
  maps__machine(node->ms.maps);

Fix it by checking if maps is NULL in fill_callchain_info().

Fixes: 0dd5041c9a0e ("perf addr_location: Add init/exit/copy functions")
Signed-off-by: Casey Chen <cachen@purestorage.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: yzhong@purestorage.com
Link: https://lore.kernel.org/r/20240722211548.61455-1-cachen@purestorage.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/callchain.c

index 1730b852a947400ff54cd75d8ec60fa3565fab61..6d075648d2ccf43c464461547ba5562edb385a69 100644 (file)
@@ -1141,7 +1141,7 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *samp
 int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
                        bool hide_unresolved)
 {
-       struct machine *machine = maps__machine(node->ms.maps);
+       struct machine *machine = node->ms.maps ? maps__machine(node->ms.maps) : NULL;
 
        maps__put(al->maps);
        al->maps = maps__get(node->ms.maps);