Skip to content

Commit fa7ab64

Browse files
author
Trond Myklebust
committed
NFS/localio: Fix a race in nfs_local_open_fh()
Once the clp->cl_uuid.lock has been dropped, another CPU could come in and free the struct nfsd_file that was just added. To prevent that from happening, take the RCU read lock before dropping the spin lock. Fixes: 86e0041 ("nfs: cache all open LOCALIO nfsd_file(s) in client") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Reviewed-by: Mike Snitzer <snitzer@kernel.org>
1 parent c367eea commit fa7ab64

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/nfs/localio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
278278
new = __nfs_local_open_fh(clp, cred, fh, nfl, mode);
279279
if (IS_ERR(new))
280280
return NULL;
281+
rcu_read_lock();
281282
/* try to swap in the pointer */
282283
spin_lock(&clp->cl_uuid.lock);
283284
nf = rcu_dereference_protected(*pnf, 1);
@@ -287,7 +288,6 @@ nfs_local_open_fh(struct nfs_client *clp, const struct cred *cred,
287288
rcu_assign_pointer(*pnf, nf);
288289
}
289290
spin_unlock(&clp->cl_uuid.lock);
290-
rcu_read_lock();
291291
}
292292
nf = nfs_local_file_get(nf);
293293
rcu_read_unlock();

0 commit comments

Comments
 (0)