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: 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>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Leo Yan <leo.yan@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH] perf buildid: Avoid copy of uninitialized memory
Date: Thu, 19 Jan 2023 22:15:00 -0300	[thread overview]
Message-ID: <Y8nrFOt/Vf8qbfhC@kernel.org> (raw)
In-Reply-To: <CAP-5=fVWgHGxUqvn2pw8+dfQ7gXpLHJA0ewQUuR-sgH10744aA@mail.gmail.com>

Em Thu, Jan 19, 2023 at 08:57:21AM -0800, Ian Rogers escreveu:
> On Thu, Jan 19, 2023 at 8:39 AM Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> >
> > Em Thu, Jan 19, 2023 at 01:29:30PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Thu, Jan 19, 2023 at 08:08:13AM -0800, Ian Rogers escreveu:
> > > > On Fri, Jan 13, 2023 at 10:57 AM Ian Rogers <irogers@google.com> wrote:
> > > > >
> > > > > build_id__init only copies the buildid data up to size leaving the
> > > > > rest of the data array uninitialized. Copying the full array during
> > > > > synthesis means the written event contains uninitialized memory.  This
> > > > > was detected by the Clang/LLVM memory sanitizer.
> > > > >
> > > > > Signed-off-by: Ian Rogers <irogers@google.com>
> > > > > ---
> > > > >  tools/perf/util/synthetic-events.c | 2 +-
> > > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> > > > > index 3ab6a92b1a6d..348d05e4ec03 100644
> > > > > --- a/tools/perf/util/synthetic-events.c
> > > > > +++ b/tools/perf/util/synthetic-events.c
> > > > > @@ -2219,7 +2219,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool, struct dso *pos, u16
> > > > >
> > > > >         len = pos->long_name_len + 1;
> > > > >         len = PERF_ALIGN(len, NAME_ALIGN);
> > > > > -       memcpy(&ev.build_id.build_id, pos->bid.data, sizeof(pos->bid.data));
> > > > > +       memcpy(&ev.build_id.build_id, pos->bid.data, pos->bid.size);
> > > >
> > > > Ping. Should be an uncontroversial change to fix a copy of
> > > > uninitialized memory into the perf.data file during synthesis.
> > >
> > > Indeed, applied.
> >
> > Humm, don't we better do it as:
> >
> > +       memcpy(&ev.build_id.build_id, pos->bid.data, min(pos->bid.size, sizeof(pos->bid.data));
> >
> > Lemme check what is setting that pos->bid.size....
> >
> > Things like sysfs__read_build_id() that does such checks, but perhaps we
> > should be defensive and do it in this function as well?
> 
> Defensive is good, another option would be an assert but they can be
> compiled out. Do you want me to repost?

Please.

- Arnaldo

      reply	other threads:[~2023-01-20  5:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 18:57 [PATCH] perf buildid: Avoid copy of uninitialized memory Ian Rogers
2023-01-19 16:08 ` Ian Rogers
2023-01-19 16:29   ` Arnaldo Carvalho de Melo
2023-01-19 16:39     ` Arnaldo Carvalho de Melo
2023-01-19 16:57       ` Ian Rogers
2023-01-20  1:15         ` 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=Y8nrFOt/Vf8qbfhC@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.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=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=trix@redhat.com \
    /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).