From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796234514; b=TzEBR5lE9CqRO+CLt1aCMqEtVnPX0RFuJGQU1sg0r3s9lx27rzyA6m0hTsjB7QmXZEIS TqOkRKgrcyHM+/6Si3QWDGw8UTD8baYbs+uzQfOAwjhoRKunsMwJ2xOCnTyCAuXRVMZzA /4DG55NoXSiSupVGXWrSD0QbdzeTcTd6XdbZi3Q/kXw1h9TJLImiCQ4yYOYoAeZSXJJ88 jHniKLSQHu8nbm9GB2qDWzflRwtDqKQH9r9WjOeopsezWwliVWXRMjK8jPKOVGW9K5Zhn AhG3tgX0+9wl5hqSTAfQgIKzE9JSxGQIwqB9/yaYl4XQ1pU6WDhDPK/zcE+4qcf8F3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796234514; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:CC:Subject:In-Reply-To: References:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=1TnfL6gH1wqK4BJQqw+3nE1QE7bAZ4jlFPoMzIxtvhc=; b=IcBudMWzI1dDD6qocZT7slvC5nbzpsB90hDblsyzo90W93XF4WCcyh0s0C4fyi9I3lnI jbXMCeXsgRTPiqKuu0QT/3mhA3+hfEH+8Fr4qD79rkDuz0VBhRR/cnIAqoQ0h/sBT6vBr sh9DhhH3p5mDkFg9RHkcvE6wa2/WCm+jWRuTx9IfqajyporgyjiY8hVglkVExH2ND6JK8 hDIFAzBn16IsUo9nTlh8XUcKsYU6KIjezqtxjJBnXYK7cvb4DeLtXV44GdVAfEVUd/Mtb oy/bQrCJvdtXDlNkCUAIg2M3WN4JdyR1drnxbPRhA31mNpv+tMBAymD/RGh0q/HpzcA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="fG1L/QxG"; arc=none smtp.remote-ip=91.218.175.42 Received: from mta0.migadu.com (out-42.mta0.migadu.com [91.218.175.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E5ED606A32C for ; Wed, 2 Dec 2026 18:01:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7E5ED606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fG1L/QxG X-Envelope-To: linux-perf-users@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=t9/9U8x+v1nBhRs2iwsonn4XDzO0hZkmQL4skXf8Gho=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796234511; v=1; x=1796839311; b=fG1L/QxGQULULWn0R4cVWxolA6DHH7gHWdL8UqF5xqkujz6jfmldMM/9MCijNIYeyxuJOO+k +i+0oSKGnS3rYpKB4yhOPQATcDGFBMLBFYgKK1Qf7WBsFILwqB9zhNxDk2ckNRYlqig7FcIf4AL zQW+QxCJQoca7qyKNdIhB1zo= X-Envelope-To: linux-perf-users@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id bde6d26c22a00421; Wed, 02 Dec 2026 18:01:51 +0000 X-Mizu-Trace-ID: bde6d26c22a00421 X-Migadu-Flow: FLOW_OUT Date: Wed, 02 Dec 2026 18:01:48 +0000 From: Bradley Morgan To: Athira Rajeev , 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: =?US-ASCII?Q?Re=3A_=5BPATCH_V3_1/2=5D_perf_disasm_powerpc=3A_Don=27t?= =?US-ASCII?Q?_use_a_string_literal_as_the_instruction_name?= In-Reply-To: <20261202172048.99786-1-atrajeev@linux.ibm.com> References: <20261202172048.99786-1-atrajeev@linux.ibm.com> Message-ID: <7318031F-6A73-47F6-93D6-0E3DBC2F15E4@linux.dev> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 2 December 2026 17:20:47 GMT, Athira Rajeev 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 Tested-by: Bradley Morgan # Power10 >Signed-off-by: Athira Rajeev >--- >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!