From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759609AbbCDMrK (ORCPT ); Wed, 4 Mar 2015 07:47:10 -0500 Received: from mail4.hitachi.co.jp ([133.145.228.5]:58687 "EHLO mail4.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751500AbbCDMrH (ORCPT ); Wed, 4 Mar 2015 07:47:07 -0500 Message-ID: <54F6FEBF.40504@hitachi.com> Date: Wed, 04 Mar 2015 21:46:55 +0900 From: Masami Hiramatsu Organization: Hitachi, Ltd., Japan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: He Kuang CC: acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, wangnan0@huawei.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf tools: Fix possible double free on error References: <1425463302-1687-1-git-send-email-hekuang@huawei.com> In-Reply-To: <1425463302-1687-1-git-send-email-hekuang@huawei.com> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (2015/03/04 19:01), He Kuang wrote: > A double free occurred when get source file path failed. If lr->path > failed to assign a new value, it will be freed as the old path and then > be freed again during line_range__clear(), and causes this: > > $ perf probe -L do_execve -k vmlinux > *** Error in `/usr/bin/perf': double free or corruption (fasttop): > 0x0000000000a9ac50 *** > ======= Backtrace: ========= > ../lib64/libc.so.6(+0x6eeef)[0x7ffff5e44eef] > ../lib64/libc.so.6(+0x78cae)[0x7ffff5e4ecae] > ../lib64/libc.so.6(+0x79987)[0x7ffff5e4f987] > ../bin/perf[0x4ab41f] > ... > > This patch fix this problem. Good catch! Acked-by: Masami Hiramatsu Thank you, > > Signed-off-by: He Kuang > --- > tools/perf/util/probe-event.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c > index 919937e..7df30bd 100644 > --- a/tools/perf/util/probe-event.c > +++ b/tools/perf/util/probe-event.c > @@ -650,7 +650,11 @@ static int __show_line_range(struct line_range *lr, const char *module) > /* Convert source file path */ > tmp = lr->path; > ret = get_real_path(tmp, lr->comp_dir, &lr->path); > - free(tmp); /* Free old path */ > + > + /* Free old path when new path is assigned */ > + if (tmp != lr->path) > + free(tmp); > + > if (ret < 0) { > pr_warning("Failed to find source file path.\n"); > return ret; > -- Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: masami.hiramatsu.pt@hitachi.com