]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
NFSv4: Ensure the delegation cred is pinned when we call delegreturn
authorTrond Myklebust <trondmy@gmail.com>
Thu, 13 Feb 2020 19:51:07 +0000 (14:51 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Feb 2020 18:54:12 +0000 (19:54 +0100)
commit 5d63944f8206a80636ae8cb4b9107d3b49f43d37 upstream.

Ensure we don't release the delegation cred during the call to
nfs4_proc_delegreturn().

Fixes: ee05f456772d ("NFSv4: Fix races between open and delegreturn")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfs/delegation.c

index fe57b2b5314ae1ede602e3102b2321a39c35da17..5f02d922f2173b4b4b5a7a98306f9fb7ee926b58 100644 (file)
@@ -222,13 +222,18 @@ void nfs_inode_reclaim_delegation(struct inode *inode, const struct cred *cred,
 
 static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
 {
+       const struct cred *cred;
        int res = 0;
 
-       if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
-               res = nfs4_proc_delegreturn(inode,
-                               delegation->cred,
+       if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags)) {
+               spin_lock(&delegation->lock);
+               cred = get_cred(delegation->cred);
+               spin_unlock(&delegation->lock);
+               res = nfs4_proc_delegreturn(inode, cred,
                                &delegation->stateid,
                                issync);
+               put_cred(cred);
+       }
        return res;
 }