NFS: Fix dentry verifier races
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 29 Sep 2021 12:12:53 +0000 (08:12 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 4 Oct 2021 00:49:07 +0000 (20:49 -0400)
If the directory changed while we were revalidating the dentry, then
don't update the dentry verifier. There is no value in setting the
verifier to an older value, and we could end up overwriting a more up to
date verifier from a parallel revalidation.

Fixes: efeda80da38d ("NFSv4: Fix revalidation of dentries with delegations")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Tested-by: Benjamin Coddington <bcodding@redhat.com>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
fs/nfs/dir.c

index 33cfff8ea551842a25fb026d0e7d785f1c0a6b12..3fafecdb20708adf020554ca1f34da4ae11fadbe 100644 (file)
@@ -1276,13 +1276,12 @@ static bool nfs_verifier_is_delegated(struct dentry *dentry)
 static void nfs_set_verifier_locked(struct dentry *dentry, unsigned long verf)
 {
        struct inode *inode = d_inode(dentry);
+       struct inode *dir = d_inode(dentry->d_parent);
 
-       if (!nfs_verifier_is_delegated(dentry) &&
-           !nfs_verify_change_attribute(d_inode(dentry->d_parent), verf))
-               goto out;
+       if (!nfs_verify_change_attribute(dir, verf))
+               return;
        if (inode && NFS_PROTO(inode)->have_delegation(inode, FMODE_READ))
                nfs_set_verifier_delegated(&verf);
-out:
        dentry->d_time = verf;
 }