From: Jiri Olsa <jolsa@redhat.com>
To: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Cc: acme@kernel.org, linux-kernel@vger.kernel.org,
peterz@infradead.org, mingo@redhat.com,
alexander.shishkin@linux.intel.com, namhyung@kernel.org,
treeze.taeung@gmail.com, yao.jin@linux.intel.com,
kim.phillips@arm.com, naveen.n.rao@linux.vnet.ibm.com
Subject: Re: [RFC] perf tool: Fix memory corruption because of zero length symbols
Date: Wed, 25 Oct 2017 15:56:25 +0200 [thread overview]
Message-ID: <20171025135625.GA30082@krava> (raw)
In-Reply-To: <1508854806-10542-1-git-send-email-ravi.bangoria@linux.vnet.ibm.com>
On Tue, Oct 24, 2017 at 07:50:06PM +0530, Ravi Bangoria wrote:
> Perf top is often crashing at very random locations on powerpc.
> After investigating, I found the crash only happens when sample
> is of zero length symbol. Powerpc kernel has many such symbols
> which does not contain length details in vmlinux binary and thus
> start and end addresses of such symbols are same.
>
> Structure
>
> struct sym_hist {
> u64 nr_samples;
> u64 period;
> struct sym_hist_entry addr[0];
> };
>
> has last member 'addr[]' of size zero. 'addr[]' is an array of
> addresses that belongs to one symbol (function). If function
> consist of 100 instructions, 'addr' points to an array of 100
> 'struct sym_hist_entry' elements. For zero length symbol, it
> points to the *empty* array, i.e. no members in the array and
> thus offset 0 is also invalid for such array.
>
> static int __symbol__inc_addr_samples(...)
> {
> ...
> offset = addr - sym->start;
> h = annotation__histogram(notes, evidx);
> h->nr_samples++;
> h->addr[offset].nr_samples++;
> h->period += sample->period;
> h->addr[offset].period += sample->period;
> ...
> }
>
> Here, when 'addr' is same as 'sym->start', 'offset' becomes 0,
> which is valid for normal symbols but *invalid* for zero length
> symbols and thus updating h->addr[offset] causes memory corruption.
>
> Fix this by adding one dummy element for zero length symbols.
>
> Fixes: edee44be5919 ("perf annotate: Don't throw error for zero length symbols")
> Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
thanks,
jirka
next prev parent reply other threads:[~2017-10-25 13:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-24 14:20 [RFC] perf tool: Fix memory corruption because of zero length symbols Ravi Bangoria
2017-10-25 2:15 ` Namhyung Kim
2017-10-25 8:28 ` Jiri Olsa
2017-10-25 9:20 ` Naveen N. Rao
2017-10-25 14:49 ` Arnaldo Carvalho de Melo
2017-10-25 13:56 ` Jiri Olsa [this message]
2017-10-28 23:09 ` [tip:perf/urgent] perf symbols: " tip-bot for Ravi Bangoria
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=20171025135625.GA30082@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=kim.phillips@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=naveen.n.rao@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=ravi.bangoria@linux.vnet.ibm.com \
--cc=treeze.taeung@gmail.com \
--cc=yao.jin@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.