Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name
@ 2026-12-02 12:43 Athira Rajeev
  2026-12-02 12:43 ` [PATCH V2 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines Athira Rajeev
  2026-12-02 12:55 ` [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name sashiko-bot
  0 siblings, 2 replies; 4+ messages in thread
From: Athira Rajeev @ 2026-12-02 12:43 UTC (permalink / raw)
  To: acme, jolsa, adrian.hunter, james.clark, tmricht, maddy, irogers,
	namhyung, bradley.morgan
  Cc: linux-perf-users, linuxppc-dev, atrajeev, hbathini, tejas05,
	tshah, sashiko-bot

When the disassembler isn't used, disasm_line__parse_powerpc() sets the
instruction name to the string literal "".  That name is owned by the
disasm_line. disasm_line__free() does zfree(&dl->ins.name), and
check_ppc_insn() replaces it with a strdup()ed name when the raw
instruction is a memory or arithmetic one.

For instructions that check_ppc_insn() doesn't name, the literal is
passed to free(), which will make glibc abort with "free(): invalid
pointer".

Use a heap allocated empty string instead, so the name is always
something that can be freed.  This also allows check_ppc_insn() to free
the previous name before replacing it, which is done in a follow up
patch to avoid leaking it.

Fixes: 06dd4c5a561c ("perf annotate: Add disasm_line__parse() to parse raw instruction for powerpc")
Reported-by: sashiko-bot@kernel.org
Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
---
Changelog:
V2 : This is a new update in V2 to address issue
reported by Sashiko during review. disasm_line__parse_powerpc()
sets the instruction name to string literal "" which could trigger
invalid free() at later point

 tools/perf/util/disasm.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 5b9bc94be55e..a1787a9c4bfd 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -908,10 +908,17 @@ static int disasm_line__parse_powerpc(struct disasm_line *dl, struct annotate_ar
 	if (name_raw_insn[0] == '\0')
 		return -1;
 
-	if (disasm)
+	if (disasm) {
 		ret = disasm_line__parse(name, namep, rawp);
-	else
-		*namep = "";
+	} else {
+		/*
+		 * The name is freed in disasm_line__free() and may be replaced
+		 * by check_ppc_insn(), so it must be heap allocated.
+		 */
+		*namep = strdup("");
+		if (*namep == NULL)
+			return -1;
+	}
 
 	tmp_raw_insn = strndup(name_raw_insn, 11);
 	if (tmp_raw_insn == NULL)
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02 12:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:43 [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name Athira Rajeev
2026-12-02 12:43 ` [PATCH V2 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines Athira Rajeev
2026-12-02 12:59   ` sashiko-bot
2026-12-02 12:55 ` [PATCH V2 1/2] perf disasm powerpc: Don't use a string literal as the instruction name sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox