]> err.no Git - linux-2.6/commitdiff
SUNRPC: Fix a memory leak in the auth credcache code
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Sat, 9 Jun 2007 19:41:42 +0000 (15:41 -0400)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Wed, 11 Jul 2007 03:40:33 +0000 (23:40 -0400)
The leak only affects the RPCSEC_GSS caches, since they are the only ones
that are dynamically allocated...
Rename the existing rpcauth_free_credcache() to rpcauth_clear_credcache()
in order to better describe its role, then add a new function
rpcauth_destroy_credcache() that actually frees the cache in addition to
clearing it out.

Also move the call to destroy the credcache in gss_destroy() to come before
the rpc upcall pipe is unlinked.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
include/linux/sunrpc/auth.h
net/sunrpc/auth.c
net/sunrpc/auth_gss/auth_gss.c
net/sunrpc/auth_unix.c
net/sunrpc/sunrpc_syms.c

index 8ef27afeea73ddbf276c412854350998ebe9f361..3972b8414c8897b025a35dac6efa38b658e29a44 100644 (file)
@@ -143,7 +143,8 @@ int                 rpcauth_refreshcred(struct rpc_task *);
 void                   rpcauth_invalcred(struct rpc_task *);
 int                    rpcauth_uptodatecred(struct rpc_task *);
 int                    rpcauth_init_credcache(struct rpc_auth *, unsigned long);
-void                   rpcauth_free_credcache(struct rpc_auth *);
+void                   rpcauth_destroy_credcache(struct rpc_auth *);
+void                   rpcauth_clear_credcache(struct rpc_cred_cache *);
 
 static inline
 struct rpc_cred *      get_rpccred(struct rpc_cred *cred)
index 9527f2bb17449ea6808f4fffd5f73feace80442f..f6b6c81cbc3e86a592391acd297dcb23da4942ff 100644 (file)
@@ -137,9 +137,8 @@ void rpcauth_destroy_credlist(struct hlist_head *head)
  * that are not referenced.
  */
 void
-rpcauth_free_credcache(struct rpc_auth *auth)
+rpcauth_clear_credcache(struct rpc_cred_cache *cache)
 {
-       struct rpc_cred_cache *cache = auth->au_credcache;
        HLIST_HEAD(free);
        struct hlist_node *pos, *next;
        struct rpc_cred *cred;
@@ -157,6 +156,21 @@ rpcauth_free_credcache(struct rpc_auth *auth)
        rpcauth_destroy_credlist(&free);
 }
 
+/*
+ * Destroy the RPC credential cache
+ */
+void
+rpcauth_destroy_credcache(struct rpc_auth *auth)
+{
+       struct rpc_cred_cache *cache = auth->au_credcache;
+
+       if (cache) {
+               auth->au_credcache = NULL;
+               rpcauth_clear_credcache(cache);
+               kfree(cache);
+       }
+}
+
 static void
 rpcauth_prune_expired(struct rpc_auth *auth, struct rpc_cred *cred, struct hlist_head *free)
 {
index 50809086fa1b30c8fcee3e9ebee9d2378f689513..8b4c02f8befb5622d98f90bb0e763fa766c687c1 100644 (file)
@@ -665,12 +665,13 @@ gss_destroy(struct rpc_auth *auth)
        dprintk("RPC:       destroying GSS authenticator %p flavor %d\n",
                        auth, auth->au_flavor);
 
+       rpcauth_destroy_credcache(auth);
+
        gss_auth = container_of(auth, struct gss_auth, rpc_auth);
        rpc_unlink(gss_auth->dentry);
        gss_auth->dentry = NULL;
        gss_mech_put(gss_auth->mech);
 
-       rpcauth_free_credcache(auth);
        kfree(gss_auth);
        module_put(THIS_MODULE);
 }
index 82300b83045ec228a0941d25265b5ed6177c6366..5622783011a4824eea6045fbce39a4a1e57e025f 100644 (file)
@@ -50,7 +50,7 @@ static void
 unx_destroy(struct rpc_auth *auth)
 {
        dprintk("RPC:       destroying UNIX authenticator %p\n", auth);
-       rpcauth_free_credcache(auth);
+       rpcauth_clear_credcache(auth->au_credcache);
 }
 
 /*
index b99b11b11461fcffe8b3cad99d0ee20da9108b0e..3e19e7af6799a99c52f8b1dc7c8b8188127a21b2 100644 (file)
@@ -57,7 +57,7 @@ EXPORT_SYMBOL(rpcauth_unregister);
 EXPORT_SYMBOL(rpcauth_create);
 EXPORT_SYMBOL(rpcauth_lookupcred);
 EXPORT_SYMBOL(rpcauth_lookup_credcache);
-EXPORT_SYMBOL(rpcauth_free_credcache);
+EXPORT_SYMBOL(rpcauth_destroy_credcache);
 EXPORT_SYMBOL(rpcauth_init_credcache);
 EXPORT_SYMBOL(put_rpccred);