diff options
author | Jeff Layton <jlayton@redhat.com> | 2014-02-03 12:13:08 -0500 |
---|---|---|
committer | Jeff Layton <jlayton@redhat.com> | 2014-03-31 08:24:42 -0400 |
commit | bce7560d4946dcfc07b0217b1d3862ed60ff7188 (patch) | |
tree | 548ef2a83300ee6c4fede7a20be30aee13b9ca5f /fs/locks.c | |
parent | ef12e72a01f3022c55e5a8e0fa1caebdc7efcfce (diff) |
locks: consolidate checks for compatible filp->f_mode values in setlk handlers
Move this check into flock64_to_posix_lock instead of duplicating it in
two places. This also fixes a minor wart in the code where we continue
referring to the struct flock after converting it to struct file_lock.
Acked-by: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/fs/locks.c b/fs/locks.c index b49e853a9c7b..4cd25781b0a4 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -388,6 +388,18 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, | |||
388 | fl->fl_ops = NULL; | 388 | fl->fl_ops = NULL; |
389 | fl->fl_lmops = NULL; | 389 | fl->fl_lmops = NULL; |
390 | 390 | ||
391 | /* Ensure that fl->fl_filp has compatible f_mode */ | ||
392 | switch (l->l_type) { | ||
393 | case F_RDLCK: | ||
394 | if (!(filp->f_mode & FMODE_READ)) | ||
395 | return -EBADF; | ||
396 | break; | ||
397 | case F_WRLCK: | ||
398 | if (!(filp->f_mode & FMODE_WRITE)) | ||
399 | return -EBADF; | ||
400 | break; | ||
401 | } | ||
402 | |||
391 | return assign_type(fl, l->l_type); | 403 | return assign_type(fl, l->l_type); |
392 | } | 404 | } |
393 | 405 | ||
@@ -2025,23 +2037,6 @@ again: | |||
2025 | file_lock->fl_flags |= FL_SLEEP; | 2037 | file_lock->fl_flags |= FL_SLEEP; |
2026 | } | 2038 | } |
2027 | 2039 | ||
2028 | error = -EBADF; | ||
2029 | switch (flock.l_type) { | ||
2030 | case F_RDLCK: | ||
2031 | if (!(filp->f_mode & FMODE_READ)) | ||
2032 | goto out; | ||
2033 | break; | ||
2034 | case F_WRLCK: | ||
2035 | if (!(filp->f_mode & FMODE_WRITE)) | ||
2036 | goto out; | ||
2037 | break; | ||
2038 | case F_UNLCK: | ||
2039 | break; | ||
2040 | default: | ||
2041 | error = -EINVAL; | ||
2042 | goto out; | ||
2043 | } | ||
2044 | |||
2045 | error = do_lock_file_wait(filp, cmd, file_lock); | 2040 | error = do_lock_file_wait(filp, cmd, file_lock); |
2046 | 2041 | ||
2047 | /* | 2042 | /* |
@@ -2143,23 +2138,6 @@ again: | |||
2143 | file_lock->fl_flags |= FL_SLEEP; | 2138 | file_lock->fl_flags |= FL_SLEEP; |
2144 | } | 2139 | } |
2145 | 2140 | ||
2146 | error = -EBADF; | ||
2147 | switch (flock.l_type) { | ||
2148 | case F_RDLCK: | ||
2149 | if (!(filp->f_mode & FMODE_READ)) | ||
2150 | goto out; | ||
2151 | break; | ||
2152 | case F_WRLCK: | ||
2153 | if (!(filp->f_mode & FMODE_WRITE)) | ||
2154 | goto out; | ||
2155 | break; | ||
2156 | case F_UNLCK: | ||
2157 | break; | ||
2158 | default: | ||
2159 | error = -EINVAL; | ||
2160 | goto out; | ||
2161 | } | ||
2162 | |||
2163 | error = do_lock_file_wait(filp, cmd, file_lock); | 2141 | error = do_lock_file_wait(filp, cmd, file_lock); |
2164 | 2142 | ||
2165 | /* | 2143 | /* |