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] [day] [month] [year] [list]
Date:	Wed, 25 Mar 2015 01:40:57 -0700
From:	Christoph Hellwig <hch@...radead.org>
To:	Sanidhya Kashyap <sanidhya.gatech@...il.com>
Cc:	trond.myklebust@...marydata.com, anna.schumaker@...app.com,
	linux-nfs@...r.kernel.org, linux-kernel@...r.kernel.org,
	taesoo@...ech.edu, changwoo@...ech.edu, sanidhya@...ech.edu,
	blee@...ech.edu
Subject: Re: [PATCH] nfs: kstrdup() memory handling

On Sat, Mar 21, 2015 at 01:07:28PM -0400, Sanidhya Kashyap wrote:
> index 86d6214..08bf1f1 100644
> --- a/fs/nfs/nfs4client.c
> +++ b/fs/nfs/nfs4client.c
> @@ -1217,8 +1217,15 @@ int nfs4_update_server(struct nfs_server *server, const char *hostname,
>  		goto out;
>  	}
>  
> -	if (server->nfs_client->cl_hostname == NULL)
> +	if (server->nfs_client->cl_hostname == NULL) {
>  		server->nfs_client->cl_hostname = kstrdup(hostname, GFP_KERNEL);
> +		if (!server->nfs_client->cl_hostname) {
> +			error = -ENOMEM;
> +			dprintk("<-- %s(): not enough memory %d\n",
> +				__func__, error);
> +			goto out;
> +		}
> +	}
>  	nfs_server_insert_lists(server);

The function alays ensures to call nfs_server_insert_lists on each exit
path, and you add one that doesn't.

>  
>  	error = nfs_probe_destination(server);
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index 627f37c..2d8b408 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -4974,6 +4974,9 @@ nfs4_init_nonuniform_client_string(struct nfs_client *clp,
>  							RPC_DISPLAY_PROTO));
>  	rcu_read_unlock();
>  	clp->cl_owner_id = kstrdup(buf, GFP_KERNEL);
> +	if (!clp->cl_owner_id)
> +		return -ENOMEM;
> +
>  	return result;
>  }
>  
> @@ -4998,6 +5001,9 @@ nfs4_init_uniform_client_string(struct nfs_client *clp,
>  				clp->rpc_ops->version, clp->cl_minorversion,
>  				nodename);
>  	clp->cl_owner_id = kstrdup(buf, GFP_KERNEL);
> +	if (!clp->cl_owner_id)
> +		return -ENOMEM;
> +

Both these use a scnprintf + kstrdup pattern thast should be replaced by
kasprintf.  But I still don't understand why both function get away with
just returning the caller supplied buf in one case, but need a dynamic
allocation in the other case.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ