linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Chenggang Qin <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, mingo@redhat.com, mingo@kernel.org,
	a.p.zijlstra@chello.nl, efault@gmx.de, akpm@linux-foundation.org,
	yanmin.zhang@intel.com, dsahern@gmail.com, tglx@linutronix.de,
	fengguang.wu@intel.com, hpa@zytor.com, paulus@samba.org,
	linux-kernel@vger.kernel.org, arjan@linux.intel.com,
	namhyung@kernel.org, namhyung@gmail.com,
	chenggang.qcg@taobao.com
Subject: [tip:perf/core] perf symbols: Fix a mmap and munmap mismatched bug
Date: Mon, 14 Oct 2013 22:35:59 -0700	[thread overview]
Message-ID: <tip-784f3390f9bd900adfb3b0373615e105a0d9749a@git.kernel.org> (raw)
In-Reply-To: <1381451279-4109-1-git-send-email-chenggang.qin@gmail.com>

Commit-ID:  784f3390f9bd900adfb3b0373615e105a0d9749a
Gitweb:     http://git.kernel.org/tip/784f3390f9bd900adfb3b0373615e105a0d9749a
Author:     Chenggang Qin <chenggang.qcg@taobao.com>
AuthorDate: Fri, 11 Oct 2013 08:27:57 +0800
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Oct 2013 12:21:23 -0300

perf symbols: Fix a mmap and munmap mismatched bug

In function filename__read_debuglink(), while the ELF file is opend and
mmapped in elf_begin(), but if this file is considered to not be usable
during the following code, we will goto the close(fd) directly. The
elf_end() is skipped.  So, the mmaped ELF file cannot be munmapped. The
mmapped areas exist during the life of perf.

This is a memory leak.  This patch fixed this bug.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Chenggang Qin <chenggang.qcg@taobao.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Link: http://lkml.kernel.org/r/1381451279-4109-1-git-send-email-chenggang.qin@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/symbol-elf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index d6b8af3..eed0b96 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -487,27 +487,27 @@ int filename__read_debuglink(const char *filename, char *debuglink,
 
 	ek = elf_kind(elf);
 	if (ek != ELF_K_ELF)
-		goto out_close;
+		goto out_elf_end;
 
 	if (gelf_getehdr(elf, &ehdr) == NULL) {
 		pr_err("%s: cannot get elf header.\n", __func__);
-		goto out_close;
+		goto out_elf_end;
 	}
 
 	sec = elf_section_by_name(elf, &ehdr, &shdr,
 				  ".gnu_debuglink", NULL);
 	if (sec == NULL)
-		goto out_close;
+		goto out_elf_end;
 
 	data = elf_getdata(sec, NULL);
 	if (data == NULL)
-		goto out_close;
+		goto out_elf_end;
 
 	/* the start of this section is a zero-terminated string */
 	strncpy(debuglink, data->d_buf, size);
 
+out_elf_end:
 	elf_end(elf);
-
 out_close:
 	close(fd);
 out:

      parent reply	other threads:[~2013-10-15  5:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-11  0:27 [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug Chenggang Qin
2013-10-11  0:27 ` [PATCH 2/3] perf core: Fix a mmap & munmap mismatches bug in dso__load Chenggang Qin
2013-10-11  0:27 ` [PATCH 3/3] perf core: Fix a memory leak bug because symbol__delete is ignored Chenggang Qin
2013-10-15  5:35   ` [tip:perf/core] perf symbols: Fix a memory leak due to symbol__delete not being used tip-bot for Chenggang Qin
2013-10-14 14:44 ` [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug Arnaldo Carvalho de Melo
2013-10-15  5:35 ` tip-bot for Chenggang Qin [this message]

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=tip-784f3390f9bd900adfb3b0373615e105a0d9749a@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@linux.intel.com \
    --cc=chenggang.qcg@taobao.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=fengguang.wu@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@gmail.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    --cc=yanmin.zhang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).