nfsd: Drop reference in expkey_parse error cases
[firefly-linux-kernel-4.4.55.git] / fs / nfsd / export.c
index 8a6f7c924c7597d0e851a84f45ae479714856f33..7ce2c6e4e23ee11c5b2cfc0a2b056dbf6d57e6a1 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/lockd/bind.h>
 #include <linux/sunrpc/msg_prot.h>
 #include <linux/sunrpc/gss_api.h>
+#include <net/ipv6.h>
 
 #define NFSDDBG_FACILITY       NFSDDBG_EXPORT
 
@@ -150,8 +151,10 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
 
        /* now we want a pathname, or empty meaning NEGATIVE  */
        err = -EINVAL;
-       if ((len=qword_get(&mesg, buf, PAGE_SIZE)) < 0)
+       if ((len=qword_get(&mesg, buf, PAGE_SIZE)) < 0) {
+               cache_put(&ek->h, &svc_expkey_cache);
                goto out;
+       }
        dprintk("Path seems to be <%s>\n", buf);
        err = 0;
        if (len == 0) {
@@ -163,8 +166,10 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
        } else {
                struct nameidata nd;
                err = path_lookup(buf, 0, &nd);
-               if (err)
+               if (err) {
+                       cache_put(&ek->h, &svc_expkey_cache);
                        goto out;
+               }
 
                dprintk("Found the path %s\n", buf);
                key.ek_path = nd.path;
@@ -1022,7 +1027,7 @@ exp_export(struct nfsctl_export *nxp)
        /* Look up the dentry */
        err = path_lookup(nxp->ex_path, 0, &nd);
        if (err)
-               goto out_unlock;
+               goto out_put_clp;
        err = -EINVAL;
 
        exp = exp_get_by_name(clp, nd.path.mnt, nd.path.dentry, NULL);
@@ -1089,9 +1094,9 @@ finish:
                exp_put(exp);
        if (fsid_key && !IS_ERR(fsid_key))
                cache_put(&fsid_key->h, &svc_expkey_cache);
-       if (clp)
-               auth_domain_put(clp);
        path_put(&nd.path);
+out_put_clp:
+       auth_domain_put(clp);
 out_unlock:
        exp_writeunlock();
 out:
@@ -1548,6 +1553,7 @@ exp_addclient(struct nfsctl_client *ncp)
 {
        struct auth_domain      *dom;
        int                     i, err;
+       struct in6_addr addr6;
 
        /* First, consistency check. */
        err = -EINVAL;
@@ -1566,9 +1572,10 @@ exp_addclient(struct nfsctl_client *ncp)
                goto out_unlock;
 
        /* Insert client into hashtable. */
-       for (i = 0; i < ncp->cl_naddr; i++)
-               auth_unix_add_addr(ncp->cl_addrlist[i], dom);
-
+       for (i = 0; i < ncp->cl_naddr; i++) {
+               ipv6_addr_set_v4mapped(ncp->cl_addrlist[i].s_addr, &addr6);
+               auth_unix_add_addr(&addr6, dom);
+       }
        auth_unix_forget_old(dom);
        auth_domain_put(dom);