From: Adrian Hunter <adrian.hunter@intel.com>
To: Ian Rogers <irogers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Leo Yan <leo.yan@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf symbol: Avoid use after free
Date: Wed, 29 Mar 2023 07:52:29 +0300 [thread overview]
Message-ID: <67d81a70-1adc-dad4-4592-5e7d67e6c926@intel.com> (raw)
In-Reply-To: <20230328234413.1081014-1-irogers@google.com>
On 29/03/23 02:44, Ian Rogers wrote:
> If demangling succeeds then sym_name is set to the demangled string
> that is freed. Rather than test if sym_name is empty and possibly
> use-after-free on the return path, expand out the alternatives.
Looks the same as:
https://lore.kernel.org/linux-perf-users/20230316194156.8320-2-adrian.hunter@intel.com/
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/util/symbol-elf.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index c0a2de42c51b..b7e3e492bff3 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -577,15 +577,17 @@ static bool get_plt_got_name(GElf_Shdr *shdr, size_t i,
> /* Get the associated symbol */
> gelf_getsym(di->dynsym_data, vr->sym_idx, &sym);
> sym_name = elf_sym__name(&sym, di->dynstr_data);
> - demangled = demangle_sym(di->dso, 0, sym_name);
> - if (demangled != NULL)
> - sym_name = demangled;
> -
> - snprintf(buf, buf_sz, "%s@plt", sym_name);
> -
> - free(demangled);
> + if (*sym_name == '\0')
> + return false;
>
> - return *sym_name;
> + demangled = demangle_sym(di->dso, 0, sym_name);
> + if (demangled != NULL) {
> + snprintf(buf, buf_sz, "%s@plt", demangled);
> + free(demangled);
> + } else {
> + snprintf(buf, buf_sz, "%s@plt", sym_name);
> + }
> + return true;
> }
>
> static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf,
next prev parent reply other threads:[~2023-03-29 4:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 23:44 Ian Rogers
2023-03-29 4:52 ` Adrian Hunter [this message]
2023-03-29 5:35 ` Ian Rogers
2023-03-29 12:53 ` Arnaldo Carvalho de Melo
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=67d81a70-1adc-dad4-4592-5e7d67e6c926@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--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®