All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Song Liu <liu.song.a23@gmail.com>
Cc: open list <linux-kernel@vger.kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	acme@kernel.org
Subject: Re: perf segfault in in ordered_events__free()
Date: Wed, 16 Jan 2019 22:34:25 +0100	[thread overview]
Message-ID: <20190116213425.GA16366@krava> (raw)
In-Reply-To: <CAPhsuW4EiGUo=p=KYsu+kGWVFRoxEjF3Bq_32QvakQjCsAAjFQ@mail.gmail.com>

On Wed, Jan 16, 2019 at 10:57:49AM -0800, Song Liu wrote:
> Hi,
> 
> We are debugging a segfault of perf in ordered_events__free().

hi,
any backtrace or info on how to reproduce it?

> Disassemble shows the segfault was caused by oe->buff == NULL
> in the following line:
> 
>         /*
>          * Current buffer might not have all the events allocated
>          * yet, we need to free only allocated ones ...
>          */
>         list_del(&oe->buffer->list);
> 
> After poking around the code, I suspect it is caused by the following
> condition in alloc_event():
> 
>         } else if (oe->buffer) {
>                 new = &oe->buffer->event[oe->buffer_idx];
>                 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
>                         oe->buffer = NULL;


argh.. yea, we need to check oe->buffer in ordered_events__free

would attached change fix it for you?

thanks,
jirka


---
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) {

  reply	other threads:[~2019-01-16 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-16 18:57 perf segfault in in ordered_events__free() Song Liu
2019-01-16 21:34 ` Jiri Olsa [this message]
2019-01-16 21:53   ` Song Liu
2019-01-17  7:33     ` Song Liu
2019-01-17  9:18       ` Jiri Olsa

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=20190116213425.GA16366@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liu.song.a23@gmail.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.