Skip to content

Commit fcfa447

Browse files
bcodding-rhamschuma-ntap
authored andcommitted
NFS: Revert "NFS: Move the flock open mode check into nfs_flock()"
Commit e129372 "NFS: Move the flock open mode check into nfs_flock()" changed NFSv3 behavior for flock() such that the open mode must match the lock type, however that requirement shouldn't be enforced for flock(). Signed-off-by: Benjamin Coddington <[email protected]> Cc: [email protected] # v4.12 Signed-off-by: Anna Schumaker <[email protected]>
1 parent f02fee2 commit fcfa447

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

fs/nfs/file.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -829,23 +829,9 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
829829
if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
830830
is_local = 1;
831831

832-
/*
833-
* VFS doesn't require the open mode to match a flock() lock's type.
834-
* NFS, however, may simulate flock() locking with posix locking which
835-
* requires the open mode to match the lock type.
836-
*/
837-
switch (fl->fl_type) {
838-
case F_UNLCK:
832+
/* We're simulating flock() locks using posix locks on the server */
833+
if (fl->fl_type == F_UNLCK)
839834
return do_unlk(filp, cmd, fl, is_local);
840-
case F_RDLCK:
841-
if (!(filp->f_mode & FMODE_READ))
842-
return -EBADF;
843-
break;
844-
case F_WRLCK:
845-
if (!(filp->f_mode & FMODE_WRITE))
846-
return -EBADF;
847-
}
848-
849835
return do_setlk(filp, cmd, fl, is_local);
850836
}
851837
EXPORT_SYMBOL_GPL(nfs_flock);

fs/nfs/nfs4proc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6709,6 +6709,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
67096709
!test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
67106710
return -ENOLCK;
67116711

6712+
/*
6713+
* Don't rely on the VFS having checked the file open mode,
6714+
* since it won't do this for flock() locks.
6715+
*/
6716+
switch (request->fl_type) {
6717+
case F_RDLCK:
6718+
if (!(filp->f_mode & FMODE_READ))
6719+
return -EBADF;
6720+
break;
6721+
case F_WRLCK:
6722+
if (!(filp->f_mode & FMODE_WRITE))
6723+
return -EBADF;
6724+
}
6725+
67126726
status = nfs4_set_lock_state(state, request);
67136727
if (status != 0)
67146728
return status;

0 commit comments

Comments
 (0)