public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Jianping Liu <frankljpliu@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, wangming01@loongson.cn, wangrui@loongson.cn,
	frankljpliu@gmail.com
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jianping Liu <frankjpliu@tencent.com>
Subject: [PATCH] perf annotate: Fix NULL pointer dereference in  loongarch_call__parse
Date: Thu, 23 Apr 2026 13:31:02 +0800	[thread overview]
Message-ID: <20260423053102.3717015-1-frankljpliu@gmail.com> (raw)

loongarch_call__parse() dereferences the return value of strchr()
without NULL check:

  name = strchr(endptr, '<');
  name++;

When objdump output for a 'bl' (branch-and-link) instruction does not
contain a symbol name delimited by '<' and '>' (e.g., when the call
target has no associated symbol), strchr() returns NULL, and the
subsequent name++ produces a wild pointer (0x1). This leads to a
segmentation fault when strchr() is later called with this invalid
pointer:

  #0  __strchr_lasx () from /lib64/libc.so.6
  #1  loongarch_call__parse () at arch/loongarch/annotate/instructions.c:29
  #2  disasm_line__init_ins () at util/annotate.c:1205
  ...

The objdump line triggering the crash looks like:

  bl              98824   # 0x9000000000641ea0

Note the absence of "<function_name>" after the address.

Add a NULL check for the return value of strchr() before dereferencing
it, consistent with s390_call__parse() which handles the same case
correctly.

Fixes: 4ca0d340ce20 ("perf annotate: Fix instruction association and parsing for LoongArch")
Signed-off-by: Jianping Liu <frankjpliu@tencent.com>
Reviewed-by: Ming Wang <wangming01@loongson.cn>
---
 tools/perf/util/annotate-arch/annotate-loongarch.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/perf/util/annotate-arch/annotate-loongarch.c
index c2addca77320..0179062a6cf9 100644
--- a/tools/perf/util/annotate-arch/annotate-loongarch.c
+++ b/tools/perf/util/annotate-arch/annotate-loongarch.c
@@ -29,6 +29,9 @@ static int loongarch_call__parse(const struct arch *arch, struct ins_operands *o
 	ops->target.addr = strtoull(c, &endptr, 16);
 
 	name = strchr(endptr, '<');
+	if (name == NULL)
+		return -1;
+
 	name++;
 
 	if (arch->objdump.skip_functions_char &&
-- 
2.43.7


             reply	other threads:[~2026-04-23  5:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23  5:31 Jianping Liu [this message]
2026-04-23  5:54 ` [PATCH] perf annotate: Fix NULL pointer dereference in loongarch_call__parse sashiko-bot

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=20260423053102.3717015-1-frankljpliu@gmail.com \
    --to=frankljpliu@gmail.com \
    --cc=acme@kernel.org \
    --cc=frankjpliu@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=wangming01@loongson.cn \
    --cc=wangrui@loongson.cn \
    /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