aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/nfs4proc.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2012-04-18 12:48:35 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-04-19 13:23:08 -0400
commit55725513b5ef9d462aa3e18527658a0362aaae83 (patch)
treee258eff89b9c1b72a4c1e6ff136ddd477c8ca9ef /fs/nfs/nfs4proc.c
parent05ffe24f5290dc095f98fbaf84afe51ef404ccc5 (diff)
NFSv4: Ensure that we check lock exclusive/shared type against open modes
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> Cc: stable@vger.kernel.org
Diffstat (limited to 'fs/nfs/nfs4proc.c')
-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 3c787d02131b..ba837d977a1a 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -4726,6 +4726,20 @@ nfs4_proc_lock(struct file *filp, int cmd, struct file_lock *request)
4726 4726
4727 if (state == NULL) 4727 if (state == NULL)
4728 return -ENOLCK; 4728 return -ENOLCK;
4729 /*
4730 * Don't rely on the VFS having checked the file open mode,
4731 * since it won't do this for flock() locks.
4732 */
4733 switch (request->fl_type & (F_RDLCK|F_WRLCK|F_UNLCK)) {
4734 case F_RDLCK:
4735 if (!(filp->f_mode & FMODE_READ))
4736 return -EBADF;
4737 break;
4738 case F_WRLCK:
4739 if (!(filp->f_mode & FMODE_WRITE))
4740 return -EBADF;
4741 }
4742
4729 do { 4743 do {
4730 status = nfs4_proc_setlk(state, cmd, request); 4744 status = nfs4_proc_setlk(state, cmd, request);
4731 if ((status != -EAGAIN) || IS_SETLK(cmd)) 4745 if ((status != -EAGAIN) || IS_SETLK(cmd))