All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Wang Nan <wangnan0@huawei.com>
Cc: namhyung@kernel.org, lizefan@huawei.com, pi3orama@163.com,
	linux-kernel@vger.kernel.org, jolsa@kernel.org,
	masami.hiramatsu.pt@hitachi.com
Subject: Re: [PATCH 1/2] perf probe: Only call probe_file__get_events() when fd is valid
Date: Thu, 5 Nov 2015 11:57:47 -0300	[thread overview]
Message-ID: <20151105145747.GQ13236@kernel.org> (raw)
In-Reply-To: <1446729565-27592-2-git-send-email-wangnan0@huawei.com>

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?

- 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 <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> ---
>  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

  parent reply	other threads:[~2015-11-05 14:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 13:19 [PATCH 0/2] perf tools: Two bugfixs related to perf probe Wang Nan
2015-11-05 13:19 ` [PATCH 1/2] perf probe: Only call probe_file__get_events() when fd is valid Wang Nan
2015-11-05 14:23   ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-05 14:57   ` Arnaldo Carvalho de Melo [this message]
2015-11-05 15:07     ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-05 15:58       ` 'Arnaldo Carvalho de Melo'
2015-11-06  9:50         ` [PATCH v2] perf probe: Verify parameters for two functions Wang Nan
2015-11-06 10:03           ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-11  7:00           ` Wangnan (F)
2015-11-12  6:43           ` [tip:perf/urgent] perf probe: Verify parameters in " tip-bot for Wang Nan
2015-11-05 13:19 ` [PATCH 2/2] perf tools: Fix find_perf_probe_point_from_map() which incorrectly returns success Wang Nan
2015-11-05 14:08   ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-05 16:00     ` acme
2015-11-06  6:28       ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-06  7:12         ` 平松雅巳 / HIRAMATU,MASAMI
2015-11-06  8:30           ` Wangnan (F)
2015-11-06  9:27             ` Wangnan (F)
2015-11-06 13:43               ` Arnaldo Carvalho de Melo
2015-11-08  7:31   ` [tip:perf/urgent] perf tools: Fix find_perf_probe_point_from_map( ) " tip-bot for Wang Nan

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=20151105145747.GQ13236@kernel.org \
    --to=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    --cc=wangnan0@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.