lkml.org 
[lkml]   [2019]   [Jan]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH perf/urgent] perf tools: Fix crash in ordered_events__free
On Thu, Jan 17, 2019 at 3:54 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Song Liu reported crash in perf record:
>
> > #0 0x0000000000500055 in ordered_events(float, long double,...)(...) ()
> > #1 0x0000000000500196 in ordered_events.reinit ()
> > #2 0x00000000004fe413 in perf_session.process_events ()
> > #3 0x0000000000440431 in cmd_record ()
> > #4 0x00000000004a439f in run_builtin ()
> > #5 0x000000000042b3e5 in main ()"
>
> This can happen when we get out of the buffers during
> event processing. The subsequent ordered_events__free
> assumes the oe->buffer != NULL and crashes. Adding
> the check to prevent that.
>
> Cc: Stephane Eranian <eranian@google.com>
> Fixes: d5ceb62b3654 ("perf ordered_events: Add 'struct ordered_events_buffer' layer")
> Reported-by: Song Liu <liu.song.a23@gmail.com>
> Link: http://lkml.kernel.org/n/tip-914bml5kabz2m9mbywd7el9l@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Reviewed-and-tested-by: Song Liu <songliubraving@fb.com>

Thanks again for the fix!
Song



> ---
> tools/perf/util/ordered-events.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
> index 897589507d97..ea523d3b248f 100644
> --- a/tools/perf/util/ordered-events.c
> +++ b/tools/perf/util/ordered-events.c
> @@ -391,8 +391,10 @@ void ordered_events__free(struct ordered_events *oe)
> * Current buffer might not have all the events allocated
> * yet, we need to free only allocated ones ...
> */
> - list_del(&oe->buffer->list);
> - ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
> + if (oe->buffer) {
> + list_del(&oe->buffer->list);
> + ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
> + }
>
> /* ... and continue with the rest */
> list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) {
> --
> 2.17.2
>

\
 
 \ /
  Last update: 2019-01-17 15:03    [W:0.112 / U:0.432 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site