perf tool: fix dereferencing NULL al->maps
PATCH v4 1/1 perf tool: fix dereferencing NULL al->maps
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().
--- tools/perf/util/callchain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/callchain.c +1 -1
@@ -1141,7 +1141,7 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sampint 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);
Signature · 1 line
2.45.2
Quoted 14 lines · Casey Chen
With
0dd5041c9a0e("perfaddr_location: Addinit/exit/copyfunctions"), when cpumode is 3 (macroPERF_RECORD_MISC_HYPERVISOR),thread__find_map()could return withal->mapsbeing NULL.The path below could add a
callchain_cursor_nodewith 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)
Quoted 6 lines
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().
Thanks for doing this. Can:
be assumed?
Thanks,
Ian
Quoted 20 lines
--- tools/perf/util/callchain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/callchain.c +1
-2@@ -1141,7 +1141,7 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *sampint 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); --2.45.2