From: Athira Rajeev <atrajeev@linux.ibm.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf disasm: Fix potential use-after-free on fileloc
Date: Sat, 21 Mar 2026 09:57:27 +0530 [thread overview]
Message-ID: <3974DCAD-373F-4C30-8535-0FBF017B87D5@linux.ibm.com> (raw)
In-Reply-To: <20260306191614.2064618-1-irogers@google.com>
> On 7 Mar 2026, at 12:46 AM, Ian Rogers <irogers@google.com> wrote:
>
> The fileloc is a copy of a pointer to a string but in places like
> symbol_disassemble__llvm this string appears to be freed setting up
> potential use-after-frees:
>
> llvm.c:
> ```
> dl = disasm_line__new(args);
> if (dl == NULL)
> goto err;
>
> annotation_line__add(&dl->al, ¬es->src->source);
>
> free(args->fileloc);
> ```
> disasm.c:
> ```
> static void annotation_line__init(struct annotation_line *al,
> struct annotate_args *args,
> int nr)
> {
> al->offset = args->offset;
> al->line = strdup(args->line);
> al->line_nr = args->line_nr;
> al->fileloc = args->fileloc;
> al->data_nr = nr;
> }
>
> struct disasm_line *disasm_line__new(struct annotate_args *args)
> {
> struct disasm_line *dl = NULL;
> struct annotation *notes = symbol__annotation(args->ms->sym);
> int nr = notes->src->nr_events;
>
> dl = zalloc(disasm_line_size(nr));
> if (!dl)
> return NULL;
>
> annotation_line__init(&dl->al, args, nr);
> ```
>
> Fix this by making the fileloc a copy of the underlying string in its
> init/exit.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/util/disasm.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> index ddcc488f2e5f..b83bc14f82e1 100644
> --- a/tools/perf/util/disasm.c
> +++ b/tools/perf/util/disasm.c
> @@ -908,13 +908,14 @@ static void annotation_line__init(struct annotation_line *al,
> al->offset = args->offset;
> al->line = strdup(args->line);
> al->line_nr = args->line_nr;
> - al->fileloc = args->fileloc;
> + al->fileloc = args->fileloc ? strdup(args->fileloc) : NULL;
> al->data_nr = nr;
> }
>
> static void annotation_line__exit(struct annotation_line *al)
> {
> zfree_srcline(&al->path);
> + zfree(&al->fileloc);
Looks good to me.
Reviewed-by: Athira Rajeev <atrajeev@linux.ibm.com <mailto:atrajeev@linux.ibm.com>>
Thanks
Athira
> zfree(&al->line);
> zfree(&al->cycles);
> zfree(&al->br_cntr);
> --
> 2.53.0.473.g4a7958ca14-goog
>
prev parent reply other threads:[~2026-03-21 4:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 19:16 Ian Rogers
2026-03-21 2:51 ` Ian Rogers
2026-03-21 4:27 ` Athira Rajeev [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=3974DCAD-373F-4C30-8535-0FBF017B87D5@linux.ibm.com \
--to=atrajeev@linux.ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--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 \
/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
all inboxes | Powered by JetHome®