aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2012-04-18 12:48:35 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-05-07 08:56:31 -0700
commit95cb2c603f27af05871e3e6718b6e1e1a6f59417 (patch)
treef6ac9a662274dadbfd3cc4d1dbfaae1273952247 /fs/nfs
parent03a9f194904985d2844a2906ba02306289b0b4e7 (diff)
downloadkernel_samsung_tuna-95cb2c603f27af05871e3e6718b6e1e1a6f59417.zip
kernel_samsung_tuna-95cb2c603f27af05871e3e6718b6e1e1a6f59417.tar.gz
kernel_samsung_tuna-95cb2c603f27af05871e3e6718b6e1e1a6f59417.tar.bz2
NFSv4: Ensure that we check lock exclusive/shared type against open modes
commit 55725513b5ef9d462aa3e18527658a0362aaae83 upstream. Since we may be simulating flock() locks using NFS byte range locks, we can't rely on the VFS having checked the file open mode for us. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/nfs4proc.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index ea6b61b..3d67302 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -4558,6 +4558,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
if (state == NULL)
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 & (F_RDLCK|F_WRLCK|F_UNLCK)) {
+ case F_RDLCK:
+ if (!(filp->f_mode & FMODE_READ))
+ return -EBADF;
+ break;
+ case F_WRLCK:
+ if (!(filp->f_mode & FMODE_WRITE))
+ return -EBADF;
+ }
+
do {
status = nfs4_proc_setlk(state, cmd, request);
if ((status != -EAGAIN) || IS_SETLK(cmd))