aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Coddington <bcodding@redhat.com>2017-11-10 06:27:49 -0500
committerAnna Schumaker <Anna.Schumaker@Netapp.com>2017-11-17 16:43:52 -0500
commitfcfa447062b2061e11f68b846d61cbfe60d0d604 (patch)
treeea0a4c4cc3f5edfe9c1bdacebd9d09b379334b4b
parentf02fee227e5f21981152850744a6084ff3fa94ee (diff)
NFS: Revert "NFS: Move the flock open mode check into nfs_flock()"
Commit e12937279c8b "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 <bcodding@redhat.com> Cc: stable@vger.kernel.org # v4.12 Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
-rw-r--r--fs/nfs/file.c18
-rw-r--r--fs/nfs/nfs4proc.c14
2 files changed, 16 insertions, 16 deletions
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 0214dd1e1060..81cca49a8375 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -829,23 +829,9 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
829 if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK) 829 if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
830 is_local = 1; 830 is_local = 1;
831 831
832 /* 832 /* We're simulating flock() locks using posix locks on the server */
833 * VFS doesn't require the open mode to match a flock() lock's type. 833 if (fl->fl_type == F_UNLCK)
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:
839 return do_unlk(filp, cmd, fl, is_local); 834 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
849 return do_setlk(filp, cmd, fl, is_local); 835 return do_setlk(filp, cmd, fl, is_local);
850} 836}
851EXPORT_SYMBOL_GPL(nfs_flock); 837EXPORT_SYMBOL_GPL(nfs_flock);
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 6b23a032ee1e..56fa5a16e097 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -6709,6 +6709,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
6709 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags)) 6709 !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
6710 return -ENOLCK; 6710 return -ENOLCK;
6711 6711
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
6712 status = nfs4_set_lock_state(state, request); 6726 status = nfs4_set_lock_state(state, request);
6713 if (status != 0) 6727 if (status != 0)
6714 return status; 6728 return status;