* [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug
@ 2013-10-11 0:27 Chenggang Qin
2013-10-11 0:27 ` [PATCH 2/3] perf core: Fix a mmap & munmap mismatches bug in dso__load Chenggang Qin
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Chenggang Qin @ 2013-10-11 0:27 UTC (permalink / raw)
To: linux-kernel
Cc: root, David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Arjan van de Ven, Namhyung Kim,
Yanmin Zhang, Wu Fengguang, Mike Galbraith, Andrew Morton,
Chenggang Qin
From: root <root@core097011.sqa.cm4>
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 memory areas are mmapped is
exist during the life of perf. This is a memory leak.
This patch fixed this bug.
Thanks.
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol-elf.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 4b12bf8..b4df870 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -471,27 +471,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:
--
1.7.8.rc2.5.g815b
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] perf core: Fix a mmap & munmap mismatches bug in dso__load
2013-10-11 0:27 [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug Chenggang Qin
@ 2013-10-11 0:27 ` Chenggang Qin
2013-10-11 0:27 ` [PATCH 3/3] perf core: Fix a memory leak bug because symbol__delete is ignored Chenggang Qin
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Chenggang Qin @ 2013-10-11 0:27 UTC (permalink / raw)
To: linux-kernel
Cc: Chenggang Qin, David Ahern, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Arnaldo Carvalho de Melo, Arjan van de Ven,
Namhyung Kim, Yanmin Zhang, Wu Fengguang, Mike Galbraith,
Andrew Morton
From: Chenggang Qin <chenggang.qcg@taobao.com>
Some dsos' symsrc is neither syms_ss or runtime_ss. In this situation, the
corresponding ELF file is opened and mmapped in symsrc__init(), but they will
be not closed and munmapped in any place.
This bug can lead to mmap & munmap mismatched, the mmap areas will exist during
the life of perf. We can think this is a memory leak.
This patch fixed the bug. symsrc__destroy() is called while the opened and
mmaped ELF file has neither symtlb section nor dynsym section, and opdsec
section.
Thanks.
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index d5528e1..9675866 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -828,7 +828,8 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter)
if (syms_ss && runtime_ss)
break;
- }
+ } else
+ symsrc__destroy(ss);
}
--
1.7.8.rc2.5.g815b
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] perf core: Fix a memory leak bug because symbol__delete is ignored
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 ` 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:perf/core] perf symbols: " tip-bot for Chenggang Qin
3 siblings, 1 reply; 8+ messages in thread
From: Chenggang Qin @ 2013-10-11 0:27 UTC (permalink / raw)
To: linux-kernel
Cc: Chenggang Qin, David Ahern, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Arnaldo Carvalho de Melo, Arjan van de Ven,
Namhyung Kim, Yanmin Zhang, Wu Fengguang, Mike Galbraith,
Andrew Morton
From: Chenggang Qin <chenggang.qcg@taobao.com>
In function symbols__fixup_duplicate(), while the duplicated symbols are found,
only the rb_node are deleted. The symbol structures themself are ignored.
Then, these memory areas are lost.
This patch fixed the bug.
Thanks.
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/symbol.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 9675866..3c9aa6f 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -148,10 +148,12 @@ again:
if (choose_best_symbol(curr, next) == SYMBOL_A) {
rb_erase(&next->rb_node, symbols);
+ symbol__delete(next);
goto again;
} else {
nd = rb_next(&curr->rb_node);
rb_erase(&curr->rb_node, symbols);
+ symbol__delete(curr);
}
}
}
--
1.7.8.rc2.5.g815b
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug
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-14 14:44 ` Arnaldo Carvalho de Melo
2013-10-15 5:35 ` [tip:perf/core] perf symbols: " tip-bot for Chenggang Qin
3 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2013-10-14 14:44 UTC (permalink / raw)
To: Chenggang Qin
Cc: linux-kernel, root, David Ahern, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Arjan van de Ven, Namhyung Kim, Yanmin Zhang,
Wu Fengguang, Mike Galbraith, Andrew Morton, Chenggang Qin
Please use "perf tools: " as the prefix, I was assuming that "perf core:
" was related to the kernel code and was skipping those patches.
I'll fix up the prefix to use the standard used for the various files in
tools/perf, "perf symbols: " for this patch, for instance.
Applied this one and I'm checking the other patches from you, thanks,
- Arnaldo
^ permalink raw reply [flat|nested] 8+ messages in thread
* [tip:perf/core] perf symbols: Fix a memory leak due to symbol__delete not being used
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-bot for Chenggang Qin
0 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Chenggang Qin @ 2013-10-15 5:35 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, mingo, mingo, a.p.zijlstra, efault, akpm, yanmin.zhang,
dsahern, tglx, fengguang.wu, hpa, paulus, linux-kernel, arjan,
namhyung, namhyung, chenggang.qcg
Commit-ID: d4f74eb89199dc7bde5579783e9188841e1271e3
Gitweb: http://git.kernel.org/tip/d4f74eb89199dc7bde5579783e9188841e1271e3
Author: Chenggang Qin <chenggang.qcg@taobao.com>
AuthorDate: Fri, 11 Oct 2013 08:27:59 +0800
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 14 Oct 2013 12:21:20 -0300
perf symbols: Fix a memory leak due to symbol__delete not being used
In function symbols__fixup_duplicate(), while duplicated symbols are
found, only the rb_node is removed from the tree. The symbol structures
themself are ignored. Then, these memory areas are lost.
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.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-3-git-send-email-chenggang.qin@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/symbol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index b66c1ee..c0c3696 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -160,10 +160,12 @@ again:
if (choose_best_symbol(curr, next) == SYMBOL_A) {
rb_erase(&next->rb_node, symbols);
+ symbol__delete(next);
goto again;
} else {
nd = rb_next(&curr->rb_node);
rb_erase(&curr->rb_node, symbols);
+ symbol__delete(curr);
}
}
}
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [tip:perf/core] perf symbols: Fix a mmap and munmap mismatched bug
2013-10-11 0:27 [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug Chenggang Qin
` (2 preceding siblings ...)
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
3 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Chenggang Qin @ 2013-10-15 5:35 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, mingo, mingo, a.p.zijlstra, efault, akpm, yanmin.zhang,
dsahern, tglx, fengguang.wu, hpa, paulus, linux-kernel, arjan,
namhyung, namhyung, chenggang.qcg
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:
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug
2013-09-01 15:29 [PATCH 1/3] perf core: " Chenggang Qin
@ 2013-09-03 9:01 ` Namhyung Kim
0 siblings, 0 replies; 8+ messages in thread
From: Namhyung Kim @ 2013-09-03 9:01 UTC (permalink / raw)
To: Chenggang Qin
Cc: linux-kernel, root, David Ahern, Peter Zijlstra, Paul Mackerras,
Ingo Molnar, Arnaldo Carvalho de Melo, Arjan van de Ven,
Yanmin Zhang, Wu Fengguang, Mike Galbraith, Andrew Morton,
Chenggang Qin
Hi Chenggang,
On Sun, 1 Sep 2013 23:29:43 +0800, Chenggang Qin wrote:
> From: root <root@core097011.sqa.cm4>
>
> 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 memory areas are mmapped is
> exist during the life of perf. This is a memory leak.
> This patch fixed this bug.
> Thanks.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] perf core: Fix a mmap and munmap mismatched bug
@ 2013-09-01 15:29 Chenggang Qin
2013-09-03 9:01 ` Namhyung Kim
0 siblings, 1 reply; 8+ messages in thread
From: Chenggang Qin @ 2013-09-01 15:29 UTC (permalink / raw)
To: linux-kernel
Cc: root, David Ahern, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
Arnaldo Carvalho de Melo, Arjan van de Ven, Namhyung Kim,
Yanmin Zhang, Wu Fengguang, Mike Galbraith, Andrew Morton,
Chenggang Qin
From: root <root@core097011.sqa.cm4>
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 memory areas are mmapped is
exist during the life of perf. This is a memory leak.
This patch fixed this bug.
Thanks.
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Yanmin Zhang <yanmin.zhang@intel.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chenggang Qin <chenggang.qcg@taobao.com>
---
tools/perf/util/symbol-elf.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 4b12bf8..b4df870 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -471,27 +471,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:
--
1.7.8.rc2.5.g815b
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-10-15 5:36 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:perf/core] perf symbols: " tip-bot for Chenggang Qin
-- strict thread matches above, loose matches on Subject: below --
2013-09-01 15:29 [PATCH 1/3] perf core: " Chenggang Qin
2013-09-03 9:01 ` Namhyung Kim
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).