Skip to content

Commit ce3c4ad

Browse files
committed
NFSD: Fix possible sleep during nfsd4_release_lockowner()
nfsd4_release_lockowner() holds clp->cl_lock when it calls check_for_locks(). However, check_for_locks() calls nfsd_file_get() / nfsd_file_put() to access the backing inode's flc_posix list, and nfsd_file_put() can sleep if the inode was recently removed. Let's instead rely on the stateowner's reference count to gate whether the release is permitted. This should be a reliable indication of locks-in-use since file lock operations and ->lm_get_owner take appropriate references, which are released appropriately when file locks are removed. Reported-by: Dai Ngo <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Cc: [email protected]
1 parent fd5e363 commit ce3c4ad

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

fs/nfsd/nfs4state.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7557,16 +7557,12 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
75577557
if (sop->so_is_open_owner || !same_owner_str(sop, owner))
75587558
continue;
75597559

7560-
/* see if there are still any locks associated with it */
7561-
lo = lockowner(sop);
7562-
list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) {
7563-
if (check_for_locks(stp->st_stid.sc_file, lo)) {
7564-
status = nfserr_locks_held;
7565-
spin_unlock(&clp->cl_lock);
7566-
return status;
7567-
}
7560+
if (atomic_read(&sop->so_count) != 1) {
7561+
spin_unlock(&clp->cl_lock);
7562+
return nfserr_locks_held;
75687563
}
75697564

7565+
lo = lockowner(sop);
75707566
nfs4_get_stateowner(sop);
75717567
break;
75727568
}

0 commit comments

Comments
 (0)