aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/client.c
diff options
context:
space:
mode:
authorElena Reshetova <elena.reshetova@intel.com>2017-10-20 05:53:38 -0400
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2017-11-17 13:48:01 -0500
commit212bf41d88c06afc23e03f9b274eebf1e8dba197 (patch)
tree755a58e9b423e6e8bfe06fa2036b633a427ff42b /fs/nfs/client.c
parent2f62b5aa4814be2c511553fd6afb4d35b6c2503b (diff)
fs, nfs: convert nfs_client.cl_count from atomic_t to refcount_t
atomic_t variables are currently used to implement reference counters with the following properties: - counter is initialized to 1 using atomic_set() - a resource is freed upon counter reaching zero - once counter reaches zero, its further increments aren't allowed - counter schema uses basic atomic operations (set, inc, inc_not_zero, dec_and_test, etc.) Such atomic variables should be converted to a newly provided refcount_t type and API that prevents accidental counter overflows and underflows. This is important since overflows and underflows can lead to use-after-free situation and be exploitable. The variable nfs_client.cl_count is used as pure reference counter. Convert it to refcount_t and fix up the operations. Suggested-by: Kees Cook <keescook@chromium.org> Reviewed-by: David Windsor <dwindsor@gmail.com> Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Diffstat (limited to 'fs/nfs/client.c')
-rw-r--r--fs/nfs/client.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 22880ef6d8dd..0ac2fb1c6b63 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -163,7 +163,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
163 163
164 clp->rpc_ops = clp->cl_nfs_mod->rpc_ops; 164 clp->rpc_ops = clp->cl_nfs_mod->rpc_ops;
165 165
166 atomic_set(&clp->cl_count, 1); 166 refcount_set(&clp->cl_count, 1);
167 clp->cl_cons_state = NFS_CS_INITING; 167 clp->cl_cons_state = NFS_CS_INITING;
168 168
169 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen); 169 memcpy(&clp->cl_addr, cl_init->addr, cl_init->addrlen);
@@ -269,7 +269,7 @@ void nfs_put_client(struct nfs_client *clp)
269 269
270 nn = net_generic(clp->cl_net, nfs_net_id); 270 nn = net_generic(clp->cl_net, nfs_net_id);
271 271
272 if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) { 272 if (refcount_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
273 list_del(&clp->cl_share_link); 273 list_del(&clp->cl_share_link);
274 nfs_cb_idr_remove_locked(clp); 274 nfs_cb_idr_remove_locked(clp);
275 spin_unlock(&nn->nfs_client_lock); 275 spin_unlock(&nn->nfs_client_lock);
@@ -314,7 +314,7 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
314 sap)) 314 sap))
315 continue; 315 continue;
316 316
317 atomic_inc(&clp->cl_count); 317 refcount_inc(&clp->cl_count);
318 return clp; 318 return clp;
319 } 319 }
320 return NULL; 320 return NULL;
@@ -1006,7 +1006,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
1006 /* Copy data from the source */ 1006 /* Copy data from the source */
1007 server->nfs_client = source->nfs_client; 1007 server->nfs_client = source->nfs_client;
1008 server->destroy = source->destroy; 1008 server->destroy = source->destroy;
1009 atomic_inc(&server->nfs_client->cl_count); 1009 refcount_inc(&server->nfs_client->cl_count);
1010 nfs_server_copy_userdata(server, source); 1010 nfs_server_copy_userdata(server, source);
1011 1011
1012 server->fsid = fattr->fsid; 1012 server->fsid = fattr->fsid;
@@ -1166,7 +1166,7 @@ static int nfs_server_list_show(struct seq_file *m, void *v)
1166 clp->rpc_ops->version, 1166 clp->rpc_ops->version,
1167 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 1167 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1168 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), 1168 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
1169 atomic_read(&clp->cl_count), 1169 refcount_read(&clp->cl_count),
1170 clp->cl_hostname); 1170 clp->cl_hostname);
1171 rcu_read_unlock(); 1171 rcu_read_unlock();
1172 1172