lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20160812215517.GO27651@kernel.org>
Date:	Fri, 12 Aug 2016 18:55:17 -0300
From:	Arnaldo Carvalho de Melo <acme@...nel.org>
To:	Colin King <colin.king@...onical.com>
Cc:	Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Masami Hiramatsu <mhiramat@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Jiri Olsa <jolsa@...nel.org>, Wang Nan <wangnan0@...wei.com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf probe: check for dup and fdopen failures

Em Fri, Aug 12, 2016 at 10:44:56PM +0100, Colin King escreveu:
> From: Colin Ian King <colin.king@...onical.com>
> 
> dup and fdopen can potentially fail, so add some extra
> error handling checks rather than assuming they always work.
> 
> Signed-off-by: Colin Ian King <colin.king@...onical.com>
> ---
>  tools/perf/util/probe-file.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
> index 9aed9c3..f3df939 100644
> --- a/tools/perf/util/probe-file.c
> +++ b/tools/perf/util/probe-file.c
> @@ -133,7 +133,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag)
>  /* Get raw string list of current kprobe_events  or uprobe_events */
>  struct strlist *probe_file__get_rawlist(int fd)
>  {
> -	int ret, idx;
> +	int ret, idx, fddup;
>  	FILE *fp;
>  	char buf[MAX_CMDLEN];
>  	char *p;
> @@ -144,7 +144,12 @@ struct strlist *probe_file__get_rawlist(int fd)
>  
>  	sl = strlist__new(NULL, NULL);
>  
> -	fp = fdopen(dup(fd), "r");
> +	fddup = dup(fd);
> +	if (fddup < 0)
> +		return NULL;
> +	fp = fdopen(fddup, "r");
> +	if (!fp)

here we leak fddup, no?

> +		return NULL;

I.e. this should be:

	if (!fp) {
		close(fddup);
		return NULL;
	}

Ack?

- Arnaldo

>  	while (!feof(fp)) {
>  		p = fgets(buf, MAX_CMDLEN, fp);
>  		if (!p)
> @@ -447,10 +452,13 @@ static int probe_cache__load(struct probe_cache *pcache)
>  {
>  	struct probe_cache_entry *entry = NULL;
>  	char buf[MAX_CMDLEN], *p;
> -	int ret = 0;
> +	int ret = 0, fddup;
>  	FILE *fp;
>  
> -	fp = fdopen(dup(pcache->fd), "r");
> +	fddup = dup(pcache->fd);
> +	if (fddup < 0)
> +		return -errno;
> +	fp = fdopen(fddup, "r");
>  	if (!fp)
>  		return -EINVAL;
>  
> -- 
> 2.8.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ