NFS: Revert "NFS: Move the flock open mode check into nfs_flock()"
authorBenjamin Coddington <bcodding@redhat.com>
Fri, 10 Nov 2017 11:27:49 +0000 (06:27 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Fri, 17 Nov 2017 21:43:52 +0000 (16:43 -0500)
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>
fs/nfs/file.c
fs/nfs/nfs4proc.c

index 0214dd1e10602b4b79f7c5c136ea0ad2bc4b832b..81cca49a837506a5abff4d25447e4f4a9484b3b3 100644 (file)
@@ -829,23 +829,9 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
        if (NFS_SERVER(inode)->flags & NFS_MOUNT_LOCAL_FLOCK)
                is_local = 1;
 
-       /*
-        * VFS doesn't require the open mode to match a flock() lock's type.
-        * NFS, however, may simulate flock() locking with posix locking which
-        * requires the open mode to match the lock type.
-        */
-       switch (fl->fl_type) {
-       case F_UNLCK:
+       /* We're simulating flock() locks using posix locks on the server */
+       if (fl->fl_type == F_UNLCK)
                return do_unlk(filp, cmd, fl, is_local);
-       case F_RDLCK:
-               if (!(filp->f_mode & FMODE_READ))
-                       return -EBADF;
-               break;
-       case F_WRLCK:
-               if (!(filp->f_mode & FMODE_WRITE))
-                       return -EBADF;
-       }
-
        return do_setlk(filp, cmd, fl, is_local);
 }
 EXPORT_SYMBOL_GPL(nfs_flock);
index 6b23a032ee1e4a43b166931910869c95e3a578f3..56fa5a16e0978e73d898b4f32cd4db44b9c18221 100644 (file)
@@ -6709,6 +6709,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
            !test_bit(NFS_STATE_POSIX_LOCKS, &state->flags))
                return -ENOLCK;
 
+       /*
+        * Don't rely on the VFS having checked the file open mode,
+        * since it won't do this for flock() locks.
+        */
+       switch (request->fl_type) {
+       case F_RDLCK:
+               if (!(filp->f_mode & FMODE_READ))
+                       return -EBADF;
+               break;
+       case F_WRLCK:
+               if (!(filp->f_mode & FMODE_WRITE))
+                       return -EBADF;
+       }
+
        status = nfs4_set_lock_state(state, request);
        if (status != 0)
                return status;