Skip to content

Commit

Permalink
NFS: add checks for returned value of try_module_get()
Browse files Browse the repository at this point in the history
There is a couple of places in client code where returned value
of try_module_get() is ignored. As a result there is a small chance
to premature unload module because of unbalanced refcounting.

The patch adds error handling in that places.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
  • Loading branch information
Alexey Khoroshilov authored and Trond Myklebust committed Aug 3, 2014
1 parent 411a99a commit 1f70ef9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fs/nfs/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ struct nfs_subversion *get_nfs_version(unsigned int version)
mutex_unlock(&nfs_version_mutex);
}

if (!IS_ERR(nfs))
try_module_get(nfs->owner);
if (!IS_ERR(nfs) && !try_module_get(nfs->owner))
return ERR_PTR(-EAGAIN);
return nfs;
}

Expand Down Expand Up @@ -158,7 +158,8 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
goto error_0;

clp->cl_nfs_mod = cl_init->nfs_mod;
try_module_get(clp->cl_nfs_mod->owner);
if (!try_module_get(clp->cl_nfs_mod->owner))
goto error_dealloc;

clp->rpc_ops = clp->cl_nfs_mod->rpc_ops;

Expand Down Expand Up @@ -190,6 +191,7 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)

error_cleanup:
put_nfs_version(clp->cl_nfs_mod);
error_dealloc:
kfree(clp);
error_0:
return ERR_PTR(err);
Expand Down

0 comments on commit 1f70ef9

Please sign in to comment.