public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Colin King <colin.king@canonical.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf evsel: fix NULL pointer deference when evsel->counts is NULL
Date: Mon, 21 Jan 2013 13:53:21 +0900	[thread overview]
Message-ID: <871udfkua5.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: 1358613414-13005-1-git-send-email-colin.king@canonical.com

Hi Colin,

On Sat, 19 Jan 2013 16:36:54 +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> __perf_evsel__read_on_cpu() only bails out with -ENOMEM if
> evsel->counts is NULL and perf_evsel__alloc_counts() has returned
> an error.  If perf_evsel__alloc_counts() does not return an error
> we get an NULL pointer deference on evsel->counts->cpu[cpu]
> if evsel->counts is NULL.

perf_evsel__alloc_counts() should allocate evsel->counts when it sees
evsel->counts is NULL and return negative error code if the allocation
fails.

So I don't see any problem in current code.  With your code, it won't
try to allocate if ->counts is NULL but overwrite existing ->counts?

Thanks,
Namhyung

>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  tools/perf/util/evsel.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 1b16dd1..93acd06 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -640,7 +640,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
>  	if (FD(evsel, cpu, thread) < 0)
>  		return -EINVAL;
>  
> -	if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1) < 0)
> +	if (evsel->counts == NULL || perf_evsel__alloc_counts(evsel, cpu + 1) < 0)
>  		return -ENOMEM;
>  
>  	if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0)

  reply	other threads:[~2013-01-21  4:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-19 16:36 [PATCH] perf evsel: fix NULL pointer deference when evsel->counts is NULL Colin King
2013-01-21  4:53 ` Namhyung Kim [this message]
2013-01-23 22:02   ` Arnaldo Carvalho de Melo
2013-01-23 23:26     ` Colin Ian King

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=871udfkua5.fsf@sejong.aot.lge.com \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=colin.king@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.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