Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032793AbbKENUd (ORCPT ); Thu, 5 Nov 2015 08:20:33 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:22313 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031373AbbKENUE (ORCPT ); Thu, 5 Nov 2015 08:20:04 -0500 From: Wang Nan To: , CC: , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 1/2] perf probe: Only call probe_file__get_events() when fd is valid Date: Thu, 5 Nov 2015 13:19:24 +0000 Message-ID: <1446729565-27592-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1446729565-27592-1-git-send-email-wangnan0@huawei.com> References: <1446729565-27592-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.563B5774.0210,ss=1,re=0.000,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2011-05-27 18:58:46 X-Mirapoint-Loop-Id: d86d64cf277eb27df8dd4e40994f0ad1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1678 Lines: 53 In system with kprobe enabled but uprobe turned off, 'perf probe -d' causes segfault because it calls probe_file__get_events() with a negative fd (when deleting uprobe events). This patch validates fds before calling probe_file__get_events(). Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim --- tools/perf/builtin-probe.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 132afc9..861aa89 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -384,7 +384,11 @@ static int perf_del_probe_events(struct strfilter *filter) goto out; } - ret = probe_file__get_events(kfd, filter, klist); + if (kfd < 0) + ret = -ENOENT; + else + ret = probe_file__get_events(kfd, filter, klist); + if (ret == 0) { strlist__for_each(ent, klist) pr_info("Removed event: %s\n", ent->s); @@ -394,7 +398,11 @@ static int perf_del_probe_events(struct strfilter *filter) goto error; } - ret2 = probe_file__get_events(ufd, filter, ulist); + if (ufd < 0) + ret2 = -ENOENT; + else + ret2 = probe_file__get_events(ufd, filter, ulist); + if (ret2 == 0) { strlist__for_each(ent, ulist) pr_info("Removed event: %s\n", ent->s); -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/