From nobody Sun Feb 8 06:54:29 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C89A1480DCA for ; Thu, 22 Jan 2026 07:31:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067101; cv=none; b=fd+8qmeMc3kwaKHGyggR/iknaV50+b7tBLQtVd9KtIGgXFYQWU9klzYmj8Q4Aymz87iLzVBYCfuSaPGuoJLcjwm/ThhBww12S7NpZrkGZhHtIqoAL/3qThCKpycDA819S8P5NJJYXhez3WKrO+aQ6xQ8bFYbanrm4wFK+wjSHMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067101; c=relaxed/simple; bh=g07mjdPPiRfUbpif4I7O+jPiAdpwj1ojeHWcOHwHmJ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Cq2QVyFAc102tc2jBT+BN3cXMHM9UjQ5n80oULZSTnkVCopIjd2HLZunCBIkGi1FVWF9bQPAmnpEOW4QDO60rrsjixldUkYPbXmgjAewWMX3+C0RbGvq6o1oTBCT8/oHGaa0J2F/L+TDtCl6BCWkiJOlbych3isJgcBx9b35I6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xGUJv975; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xGUJv975" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12338749ea9so908754c88.0 for ; Wed, 21 Jan 2026 23:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067094; x=1769671894; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7SyQiS0lnXgAvEhozlNZ8ceN/SCct+/3Su0Yxs9eoEA=; b=xGUJv975qe1pESzwD6ZJ5olyGwM9PxvudWqIPDlUtdU/8ZPiFsq6ku+WIYf0MLEnDM cOFXjpQhoTgk11tu9FffB7DVzrRXwtI43Df449FU9VnBTViXgJUrreCHIiaBiJhJggPe ImyHEQj59YEVTJRopX6GlnKCM2Q6HmFozB+PRh4A0k9S5dtpi7lHybBlSgNBn2n2aPJr gMxJFz9Gp8S8nsfCOPJ0EfbLrJQIPl4qdJ/5qVlFWxlHDtVaFQVGq365scQCEWxkkMSG ylzJYZRR1aZBAM2TEjOmLgJ4TjtFPCbIBMPZCg7YGPR0VmMDXP5Sw6ShqyuX4FcVbcrG RFww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067094; x=1769671894; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7SyQiS0lnXgAvEhozlNZ8ceN/SCct+/3Su0Yxs9eoEA=; b=ESVnuortBYZKVIekySM0WGBRCifVv9n+azZlkQp28x9PzysJpMAAA2CFkNCrhCwBb/ BYC9DlAjCprbKnIYmu2hUSdW8TY76UbE5dJ2hpkildATuQ8PrmCp7LKprlpMGOAaOb0n /yY96QSLtVkOJaC9qKy7taR54JV+oalTi6yqhHzId7bcbyipmPMe7kLZVBEcEVt5p058 qfbAxgzMXqgLUk4AYScIhwUHWXVy2Khv3nSk2iBOU+fzK4iDoLmGiENL6wU+LgmfrhCu D/JZu+Sry7FRd6KfAVWgZjyV1lx7/+zYpSTsy6DDWVt1Wi/6xWy3UZ9/cE1NNP5xyJqc OmoA== X-Forwarded-Encrypted: i=1; AJvYcCUpsgzOoNXQRu8Wiupc7nyicWCR2ktf9UOJdlZWofzXIkvmYucv8AQx7FpE3ruhZB8E47N5rubasxnqNyU=@vger.kernel.org X-Gm-Message-State: AOJu0YwjT9oBMVHgiNMa6cWwU9cPlRD4koJNv6W9ZC1zy6UinjBzxMUK K8W71NKL6043hyVVHDUH1gPhrexbZcJn2o/FAx1v6bYl19uSYzk8ugvmE26WxrQG3ryqtrz2RQm BgDtfqDLMJg== X-Received: from dlbcm22.prod.google.com ([2002:a05:7022:6896:b0:11e:60ad:95af]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4584:b0:11b:c2fd:3960 with SMTP id a92af1059eb24-1244b35fd1amr12854378c88.28.1769067093485; Wed, 21 Jan 2026 23:31:33 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:18 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-3-irogers@google.com> Subject: [PATCH v1 02/11] perf annotate: Fix args leak of map_symbol From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" map_symbol__exit needs calling on an annotate_args.ms, however, rather than introduce proper reference count handling to symbol__annotate just switch to passing the map_symbol pointer parameter around, making the puts the caller's responsibility. Signed-off-by: Ian Rogers Fixes: 56e144fe9826 ("perf mem_info: Add and use map_symbol__exit and addr_= map_symbol__exit") --- tools/perf/util/annotate.c | 2 +- tools/perf/util/capstone.c | 14 +++++++------- tools/perf/util/disasm.c | 32 +++++++++++++++++--------------- tools/perf/util/disasm.h | 2 +- tools/perf/util/llvm.c | 6 +++--- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index cc7764455faf..791d60f97c23 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1031,7 +1031,7 @@ int symbol__annotate(struct map_symbol *ms, struct ev= sel *evsel, return 0; =20 args.arch =3D arch; - args.ms =3D *ms; + args.ms =3D ms; =20 if (notes->src =3D=3D NULL) { notes->src =3D annotated_source__new(); diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index be5fd44b1f9d..2c7feab61b7b 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -143,7 +143,7 @@ static void print_capstone_detail(cs_insn *insn, char *= buf, size_t len, struct annotate_args *args, u64 addr) { int i; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct symbol *sym; =20 /* TODO: support more architectures */ @@ -222,7 +222,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 offset; @@ -256,7 +256,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -268,7 +268,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -345,7 +345,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); struct nscookie nsc; u64 start =3D map__rip_2objdump(map, sym->start); @@ -382,7 +382,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -408,7 +408,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 50b9433f3f8e..96c78b01e17a 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -269,9 +269,7 @@ static int call__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s { char *endptr, *tok, *name; struct map *map =3D ms->map; - struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, - }; + struct addr_map_symbol target; =20 ops->target.addr =3D strtoull(ops->raw, &endptr, 16); =20 @@ -296,12 +294,16 @@ static int call__parse(struct arch *arch, struct ins_= operands *ops, struct map_s if (ops->target.name =3D=3D NULL) return -1; find_target: - target.addr =3D map__objdump_2mem(map, ops->target.addr); + target =3D (struct addr_map_symbol) { + .ms =3D { .map =3D map__get(map), }, + .addr =3D map__objdump_2mem(map, ops->target.addr), + }; =20 if (maps__find_ams(ms->maps, &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 + addr_map_symbol__exit(&target); return 0; =20 indirect_call: @@ -366,7 +368,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, + .ms =3D { .map =3D map__get(map), }, }; const char *c =3D strchr(ops->raw, ','); u64 start, end; @@ -440,7 +442,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s } else { ops->target.offset_avail =3D false; } - + addr_map_symbol__exit(&target); return 0; } =20 @@ -1046,7 +1048,7 @@ static size_t disasm_line_size(int nr) struct disasm_line *disasm_line__new(struct annotate_args *args) { struct disasm_line *dl =3D NULL; - struct annotation *notes =3D symbol__annotation(args->ms.sym); + struct annotation *notes =3D symbol__annotation(args->ms->sym); int nr =3D notes->src->nr_events; =20 dl =3D zalloc(disasm_line_size(nr)); @@ -1064,7 +1066,7 @@ struct disasm_line *disasm_line__new(struct annotate_= args *args) } else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) = < 0) goto out_free_line; =20 - disasm_line__init_ins(dl, args->arch, &args->ms); + disasm_line__init_ins(dl, args->arch, args->ms); } =20 return dl; @@ -1119,7 +1121,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, struct annotate_args *args, char *parsed_line, int *line_nr, char **fileloc) { - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct annotation *notes =3D symbol__annotation(sym); struct disasm_line *dl; char *tmp; @@ -1151,7 +1153,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, args->line =3D parsed_line; args->line_nr =3D *line_nr; args->fileloc =3D *fileloc; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); (*line_nr)++; @@ -1172,7 +1174,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, .ms =3D { .map =3D map, }, }; =20 - if (!maps__find_ams(args->ms.maps, &target) && + if (!maps__find_ams(args->ms->maps, &target) && target.ms.sym->start =3D=3D target.al_addr) dl->ops.target.sym =3D target.ms.sym; } @@ -1338,7 +1340,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, struct annotate_args *args) { struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 end =3D map__rip_2objdump(map, sym->end); @@ -1375,7 +1377,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -1501,7 +1503,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, struct annotate_args *args) { struct annotation_options *opts =3D &annotate_opts; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char *command; FILE *file; @@ -1644,7 +1646,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, int symbol__disassemble(struct symbol *sym, struct annotate_args *args) { struct annotation_options *options =3D args->options; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char symfs_filename[PATH_MAX]; bool delete_extract =3D false; diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index d2cb555e4a3b..a3ea9d676281 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -97,7 +97,7 @@ struct ins_ops { =20 struct annotate_args { struct arch *arch; - struct map_symbol ms; + struct map_symbol *ms; struct annotation_options *options; s64 offset; char *line; diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c index 2ebf1f5f65bf..4ada9a10bd93 100644 --- a/tools/perf/util/llvm.c +++ b/tools/perf/util/llvm.c @@ -118,7 +118,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, { #ifdef HAVE_LIBLLVM_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); /* Malloc-ed buffer containing instructions read from disk. */ @@ -184,7 +184,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -242,7 +242,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, &line_storage_len); args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 llvm_addr2line(filename, pc, &args->fileloc, (unsigned int *)&args->line_nr, false, NULL); --=20 2.52.0.457.g6b5491de43-goog