public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rabin Vincent <rabin@rab.in>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH 1/1] perf annotate: Fix fallback to unparsed disassembler line
Date: Thu, 5 Mar 2015 20:19:41 +0100	[thread overview]
Message-ID: <20150305191941.GA8759@dator> (raw)
In-Reply-To: <1425582200-28125-2-git-send-email-acme@kernel.org>

On Thu, Mar 05, 2015 at 04:03:20PM -0300, Arnaldo Carvalho de Melo wrote:
> When fixing a leak in the 0fb9f2aab738 commit ("perf annotate: Fix
> memory leaks in LOCK handling") we failed to take that into account and
> instead tried to free one of the data structures that should be freed
> only when successfully allocated, oops, segfault.
> 
> There was a change in the way the objdump output for lock prefixed
> instructions is formatted that lead the relevant parser to fail to grok
> it.
> 
> At least RHEL7 works ok, but Fedora 20 segfaults.
> 
> Fix it by making the ins__delete() destructor work like the most basic
> destructor: free().
> 
> Namely make it accept a NULL pointer and when handling it just do
> nothing.

While this patch is certainly sufficient both as a safety and as a quick
fix to the current problem (sorry about that), it seems that the real
issue is that lock__parse() returns success even on parsing failures?
The following patch fixes the issue for me without the above check.

(The removal of locked.ins == NULL in lock__scnprintf() is because it
 becomes unused after this.  On failure to parse the lock's inner
 instruction, the default printing in disasm__line__scnprintf() will be
 used, and that is identical to what this ins__raw_scnprintf() call
 does.)

8<------------
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 61bf912..51ab850 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -171,7 +171,7 @@ static int lock__parse(struct ins_operands *ops)
 
 	ops->locked.ops = zalloc(sizeof(*ops->locked.ops));
 	if (ops->locked.ops == NULL)
-		return 0;
+		return -1;
 
 	if (disasm_line__parse(ops->raw, &name, &ops->locked.ops->raw) < 0)
 		goto out_free_ops;
@@ -193,7 +193,7 @@ static int lock__parse(struct ins_operands *ops)
 
 out_free_ops:
 	zfree(&ops->locked.ops);
-	return 0;
+	return -1;
 }
 
 static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
@@ -201,9 +201,6 @@ static int lock__scnprintf(struct ins *ins, char *bf, size_t size,
 {
 	int printed;
 
-	if (ops->locked.ins == NULL)
-		return ins__raw_scnprintf(ins, bf, size, ops);
-
 	printed = scnprintf(bf, size, "%-6.6s ", ins->name);
 	return printed + ins__scnprintf(ops->locked.ins, bf + printed,
 					size - printed, ops->locked.ops);

  reply	other threads:[~2015-03-05 19:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-05 19:03 [GIT PULL 0/1] perf/urgent fix Arnaldo Carvalho de Melo
2015-03-05 19:03 ` [PATCH 1/1] perf annotate: Fix fallback to unparsed disassembler line Arnaldo Carvalho de Melo
2015-03-05 19:19   ` Rabin Vincent [this message]
2015-03-09 11:09   ` Ingo Molnar
2015-03-09 13:25     ` Arnaldo Carvalho de Melo
2015-03-05 19:33 ` [GIT PULL 0/1] perf/urgent fix Ingo Molnar

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=20150305191941.GA8759@dator \
    --to=rabin@rab.in \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --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