linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	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 09:53:27 -0300	[thread overview]
Message-ID: <ZCQ0x2Ytd22AiabX@kernel.org> (raw)
In-Reply-To: <CAP-5=fXhc-nwVp=HKmycmryYSY6sBrDKGnQ+Ogt+86sHfsT82Q@mail.gmail.com>

Em Tue, Mar 28, 2023 at 10:35:07PM -0700, Ian Rogers escreveu:
> On Tue, Mar 28, 2023 at 9:52 PM Adrian Hunter <adrian.hunter@intel.com> wrote:
> >
> > 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/
> 
> Sorry for missing that. In the case it returns false, this avoids an
> unnecessary snprintf.

I applied Adrian's fixes,

- Arnaldo
 
> Thanks,
> Ian
> 
> > >
> > > 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,
> >

-- 

- Arnaldo

      reply	other threads:[~2023-03-29 12:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 23:44 [PATCH v1] perf symbol: Avoid use after free Ian Rogers
2023-03-29  4:52 ` Adrian Hunter
2023-03-29  5:35   ` Ian Rogers
2023-03-29 12:53     ` Arnaldo Carvalho de Melo [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=ZCQ0x2Ytd22AiabX@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --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;
as well as URLs for NNTP newsgroup(s).