public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.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>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH] perf synthetic events: Avoid write of uninitialized memory.
Date: Wed, 10 Mar 2021 12:48:36 +0100	[thread overview]
Message-ID: <YEiyFNEhMuZhXA30@krava> (raw)
In-Reply-To: <20210309234945.419254-1-irogers@google.com>

On Tue, Mar 09, 2021 at 03:49:45PM -0800, Ian Rogers wrote:
> Account for alignment bytes in the zero-ing memset.
> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/synthetic-events.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index b698046ec2db..31bf3dd6a1e0 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c
> @@ -424,7 +424,7 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
>  
>  	while (!io.eof) {
>  		static const char anonstr[] = "//anon";
> -		size_t size;
> +		size_t size, aligned_size;
>  
>  		/* ensure null termination since stack will be reused. */
>  		event->mmap2.filename[0] = '\0';
> @@ -484,11 +484,12 @@ int perf_event__synthesize_mmap_events(struct perf_tool *tool,
>  		}
>  
>  		size = strlen(event->mmap2.filename) + 1;
> -		size = PERF_ALIGN(size, sizeof(u64));
> +		aligned_size = PERF_ALIGN(size, sizeof(u64));
>  		event->mmap2.len -= event->mmap.start;
>  		event->mmap2.header.size = (sizeof(event->mmap2) -
> -					(sizeof(event->mmap2.filename) - size));
> -		memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
> +					(sizeof(event->mmap2.filename) - aligned_size));
> +		memset(event->mmap2.filename + size, 0, machine->id_hdr_size +
> +			(aligned_size - size));

so we did not zero the extra alignment bytes, nice ;-) looks good

Acked-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

>  		event->mmap2.header.size += machine->id_hdr_size;
>  		event->mmap2.pid = tgid;
>  		event->mmap2.tid = pid;
> -- 
> 2.30.1.766.gb4fecdf3b7-goog
> 


  reply	other threads:[~2021-03-10 11:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09 23:49 [PATCH] perf synthetic events: Avoid write of uninitialized memory Ian Rogers
2021-03-10 11:48 ` Jiri Olsa [this message]
2021-03-10 13:13   ` 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=YEiyFNEhMuZhXA30@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@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