Skip to content

Commit c79ba78

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
NFS: Dont clobber more uptodate values in nfs_set_verifier()
nfs_lookup_revalidate and friends are not serialised, so it is currently quite possible for the dentry to be revalidated, and then have the updated verifier replaced with an older value by another process. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent ef75c79 commit c79ba78

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎fs/nfs/dir.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ int nfs_fsync_dir(struct file *filp, struct dentry *dentry, int datasync)
637637
* In the case it has, we assume that the dentries are untrustworthy
638638
* and may need to be looked up again.
639639
*/
640-
static inline int nfs_check_verifier(struct inode *dir, struct dentry *dentry)
640+
static int nfs_check_verifier(struct inode *dir, struct dentry *dentry)
641641
{
642642
if (IS_ROOT(dentry))
643643
return 1;
@@ -652,6 +652,12 @@ static inline void nfs_set_verifier(struct dentry * dentry, unsigned long verf)
652652
dentry->d_fsdata = (void *)verf;
653653
}
654654

655+
static void nfs_refresh_verifier(struct dentry * dentry, unsigned long verf)
656+
{
657+
if (time_after(verf, (unsigned long)dentry->d_fsdata))
658+
nfs_set_verifier(dentry, verf);
659+
}
660+
655661
/*
656662
* Whenever an NFS operation succeeds, we know that the dentry
657663
* is valid, so we update the revalidation timestamp.
@@ -785,7 +791,7 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
785791
goto out_bad;
786792

787793
nfs_renew_times(dentry);
788-
nfs_set_verifier(dentry, verifier);
794+
nfs_refresh_verifier(dentry, verifier);
789795
out_valid:
790796
unlock_kernel();
791797
dput(parent);
@@ -1085,7 +1091,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
10851091
verifier = nfs_save_change_attribute(dir);
10861092
ret = nfs4_open_revalidate(dir, dentry, openflags, nd);
10871093
if (!ret)
1088-
nfs_set_verifier(dentry, verifier);
1094+
nfs_refresh_verifier(dentry, verifier);
10891095
unlock_kernel();
10901096
out:
10911097
dput(parent);
@@ -1159,10 +1165,13 @@ static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc)
11591165
dentry = alias;
11601166
}
11611167

1162-
out_renew:
11631168
nfs_renew_times(dentry);
11641169
nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
11651170
return dentry;
1171+
out_renew:
1172+
nfs_renew_times(dentry);
1173+
nfs_refresh_verifier(dentry, nfs_save_change_attribute(dir));
1174+
return dentry;
11661175
}
11671176

11681177
/*
@@ -1700,7 +1709,7 @@ static int nfs_rename(struct inode *old_dir, struct dentry *old_dentry,
17001709
if (!error) {
17011710
d_move(old_dentry, new_dentry);
17021711
nfs_renew_times(new_dentry);
1703-
nfs_set_verifier(new_dentry, nfs_save_change_attribute(new_dir));
1712+
nfs_refresh_verifier(new_dentry, nfs_save_change_attribute(new_dir));
17041713
}
17051714

17061715
/* new dentry created? */

0 commit comments

Comments
 (0)