mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Casey Chen <cachen@purestorage.com>
To: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	namhyung@kernel.org
Cc: yzhong@purestorage.com, Casey Chen <cachen@purestorage.com>
Subject: [PATCHv3] perf tool: fix dereferencing NULL al->maps
Date: Sat, 20 Jul 2024 21:19:44 -0600	[thread overview]
Message-ID: <20240721031944.62913-1-cachen@purestorage.com> (raw)

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 maps__machine().
---
 tools/perf/util/maps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c
index 432399cbe5dd..d243cb794a99 100644
--- a/tools/perf/util/maps.c
+++ b/tools/perf/util/maps.c
@@ -169,7 +169,7 @@ static void maps__set_maps_by_name_sorted(struct maps *maps, bool value)
 
 struct machine *maps__machine(const struct maps *maps)
 {
-	return RC_CHK_ACCESS(maps)->machine;
+	return maps ? RC_CHK_ACCESS(maps)->machine : NULL;
 }
 
 unsigned int maps__nr_maps(const struct maps *maps)
-- 
2.45.2


             reply	other threads:[~2024-07-21  3:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-21  3:19 Casey Chen [this message]
2024-07-21  5:48 ` Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240721031944.62913-1-cachen@purestorage.com \
    --to=cachen@purestorage.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=yzhong@purestorage.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®