Linux Perf Users
 help / color / mirror / Atom feed
From: Bradley Morgan <bradley.morgan@linux.dev>
To: Athira Rajeev <atrajeev@linux.ibm.com>,
	acme@kernel.org, jolsa@kernel.org, adrian.hunter@intel.com,
	james.clark@linaro.org, tmricht@linux.ibm.com,
	maddy@linux.ibm.com, irogers@google.com, namhyung@kernel.org
Cc: linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	atrajeev@linux.ibm.com, hbathini@linux.vnet.ibm.com,
	tejas05@linux.ibm.com, tshah@linux.ibm.com,
	sashiko-bot@kernel.org
Subject: Re: [PATCH V3 1/2] perf disasm powerpc: Don't use a string literal as the instruction name
Date: Wed, 02 Dec 2026 18:01:48 +0000	[thread overview]
Message-ID: <7318031F-6A73-47F6-93D6-0E3DBC2F15E4@linux.dev> (raw)
In-Reply-To: <20261202172048.99786-1-atrajeev@linux.ibm.com>

On 2 December 2026 17:20:47 GMT, Athira Rajeev <atrajeev@linux.ibm.com>
wrote:
>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 makes 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.  Also free *namep if strndup() fails during
>raw instruction parsing to avoid leaking it on error.
>
>Fixes: 06dd4c5a561c ("perf annotate: Add disasm_line__parse() to parse raw instruction for powerpc")
>Reported-by: sashiko-bot@kernel.org

Cheers, the whole series gets

Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>

Tested-by: Bradley Morgan <bradley.morgan@linux.dev> # Power10


>Signed-off-by: Athira Rajeev <atrajeev@linux.ibm.com>
>---
>Changelog:
>V3 : Free *namep (dl->ins.name) if strndup() fails to avoid leaking
>     it on error (reported by Sashiko).
>V2 : Use strdup("") instead of string literal "" in
>     disasm_line__parse_powerpc() so disasm_line__free() does not
>     trigger an invalid free() (reported by Sashiko).
>
> tools/perf/util/disasm.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
>
>diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
>index 5b9bc94be55e..169fc5acbfc5 100644
>--- a/tools/perf/util/disasm.c
>+++ b/tools/perf/util/disasm.c
>@@ -908,14 +908,23 @@ 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)
>+	if (tmp_raw_insn == NULL) {
>+		zfree(namep);
> 		return -1;
>+	}
> 
> 	remove_spaces(tmp_raw_insn);
> 
>

--- Thanks!

      parent reply	other threads:[~2026-12-02 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 17:20 [PATCH V3 1/2] perf disasm powerpc: Don't use a string literal as the instruction name Athira Rajeev
2026-12-02 17:20 ` [PATCH V3 2/2] perf disasm powerpc: handle Power10 prefixed instruction continuation lines Athira Rajeev
2026-12-02 17:37 ` [PATCH V3 1/2] perf disasm powerpc: Don't use a string literal as the instruction name sashiko-bot
2026-12-02 18:01 ` Bradley Morgan [this message]

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=7318031F-6A73-47F6-93D6-0E3DBC2F15E4@linux.dev \
    --to=bradley.morgan@linux.dev \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=atrajeev@linux.ibm.com \
    --cc=hbathini@linux.vnet.ibm.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=namhyung@kernel.org \
    --cc=sashiko-bot@kernel.org \
    --cc=tejas05@linux.ibm.com \
    --cc=tmricht@linux.ibm.com \
    --cc=tshah@linux.ibm.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