Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033216AbbKEP6h (ORCPT ); Thu, 5 Nov 2015 10:58:37 -0500 Received: from mail.kernel.org ([198.145.29.136]:42573 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031507AbbKEP6g (ORCPT ); Thu, 5 Nov 2015 10:58:36 -0500 Date: Thu, 5 Nov 2015 12:58:30 -0300 From: "'Arnaldo Carvalho de Melo'" To: =?utf-8?B?5bmz5p2+6ZuF5bezIC8gSElSQU1BVFXvvIxNQVNBTUk=?= Cc: Wang Nan , "namhyung@kernel.org" , "lizefan@huawei.com" , "pi3orama@163.com" , "linux-kernel@vger.kernel.org" , "jolsa@kernel.org" Subject: Re: [PATCH 1/2] perf probe: Only call probe_file__get_events() when fd is valid Message-ID: <20151105155830.GV13236@kernel.org> References: <1446729565-27592-1-git-send-email-wangnan0@huawei.com> <1446729565-27592-2-git-send-email-wangnan0@huawei.com> <20151105145747.GQ13236@kernel.org> <50399556C9727B4D88A595C8584AAB3752604E04@GSjpTKYDCembx32.service.hitachi.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <50399556C9727B4D88A595C8584AAB3752604E04@GSjpTKYDCembx32.service.hitachi.net> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3621 Lines: 113 Em Thu, Nov 05, 2015 at 03:07:23PM +0000, 平松雅巳 / HIRAMATU,MASAMI escreveu: > From: Arnaldo Carvalho de Melo [mailto:acme@kernel.org] > >Em Thu, Nov 05, 2015 at 01:19:24PM +0000, Wang Nan escreveu: > >> 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(). > > > >Wouldn't this shorter patch be more robust by deferring the validation > >to just before using the 'fd' value? > > > >The end result is that probe_file__get_events() will return -ENOENT in > >both calls, so ret and ret2 will both be set to -ENOENT, as in your > >patch. > > > >Masami? > > Yes, I've suggested so :) Kinda, you suggested to check at probe_file__get_events() , while I am suggesting to check even deeper, just before the actual use of fd, in probe_file__get_rawlist(). - Arnaldo > https://lkml.org/lkml/2015/11/5/353 > > Thanks! > > > > > > >- Arnaldo > > > >diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c > >index 89dbeb92c68e..f04a8318a1a7 100644 > >--- a/tools/perf/util/probe-file.c > >+++ b/tools/perf/util/probe-file.c > >@@ -138,6 +138,9 @@ struct strlist *probe_file__get_rawlist(int fd) > > char *p; > > struct strlist *sl; > > > >+ if (fd < 0) > >+ return NULL; > >+ > > sl = strlist__new(NULL, NULL); > > > > fp = fdopen(dup(fd), "r"); > > > > > >diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c > >index 89dbeb92c68e..e5dc8e62f0f1 100644 > >--- a/tools/perf/util/probe-file.c > >+++ b/tools/perf/util/probe-file.c > >@@ -169,6 +169,9 @@ static struct strlist *__probe_file__get_namelist(int fd, bool include_group) > > struct probe_trace_event tev; > > int ret = 0; > > > >+ if (fd < 0) > >+ return NULL; > >+ > > memset(&tev, 0, sizeof(tev)); > > rawlist = probe_file__get_rawlist(fd); > > if (!rawlist) > > > > > >> 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/