Skip to content

Commit

Permalink
lockd: ensure we use the correct file descriptor when unlocking
Browse files Browse the repository at this point in the history
Shared locks are set on O_RDONLY descriptors and exclusive locks are set
on O_WRONLY ones. nlmsvc_unlock however calls vfs_lock_file twice, once
for each descriptor, but it doesn't reset fl_file. Ensure that it does.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
  • Loading branch information
Jeff Layton authored and Chuck Lever committed Dec 10, 2022
1 parent 75c7940 commit 69efce0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fs/lockd/svclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,13 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
nlmsvc_cancel_blocked(net, file, lock);

lock->fl.fl_type = F_UNLCK;
if (file->f_file[O_RDONLY])
error = vfs_lock_file(file->f_file[O_RDONLY], F_SETLK,
lock->fl.fl_file = file->f_file[O_RDONLY];
if (lock->fl.fl_file)
error = vfs_lock_file(lock->fl.fl_file, F_SETLK,
&lock->fl, NULL);
if (file->f_file[O_WRONLY])
error = vfs_lock_file(file->f_file[O_WRONLY], F_SETLK,
lock->fl.fl_file = file->f_file[O_WRONLY];
if (lock->fl.fl_file)
error |= vfs_lock_file(lock->fl.fl_file, F_SETLK,
&lock->fl, NULL);

return (error < 0)? nlm_lck_denied_nolocks : nlm_granted;
Expand Down

0 comments on commit 69efce0

Please sign in to comment.