Skip to content

Commit

Permalink
lockd: set other missing fields when unlocking files
Browse files Browse the repository at this point in the history
[ Upstream commit 18ebd35 ]

vfs_lock_file() expects the struct file_lock to be fully initialised by
the caller. Re-exported NFSv3 has been seen to Oops if the fl_file field
is NULL.

Fixes: aec1582 ("lockd: set fl_owner when unlocking files")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216582
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Trond Myklebust authored and gregkh committed Dec 31, 2022
1 parent 318229b commit 95d42a8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions fs/lockd/svcsubs.c
Expand Up @@ -176,20 +176,23 @@ nlm_delete_file(struct nlm_file *file)
}
}

static int nlm_unlock_files(struct nlm_file *file, fl_owner_t owner)
static int nlm_unlock_files(struct nlm_file *file, const struct file_lock *fl)
{
struct file_lock lock;

locks_init_lock(&lock);
lock.fl_type = F_UNLCK;
lock.fl_start = 0;
lock.fl_end = OFFSET_MAX;
lock.fl_owner = owner;
if (file->f_file[O_RDONLY] &&
vfs_lock_file(file->f_file[O_RDONLY], F_SETLK, &lock, NULL))
lock.fl_owner = fl->fl_owner;
lock.fl_pid = fl->fl_pid;
lock.fl_flags = FL_POSIX;

lock.fl_file = file->f_file[O_RDONLY];
if (lock.fl_file && vfs_lock_file(lock.fl_file, F_SETLK, &lock, NULL))
goto out_err;
if (file->f_file[O_WRONLY] &&
vfs_lock_file(file->f_file[O_WRONLY], F_SETLK, &lock, NULL))
lock.fl_file = file->f_file[O_WRONLY];
if (lock.fl_file && vfs_lock_file(lock.fl_file, F_SETLK, &lock, NULL))
goto out_err;
return 0;
out_err:
Expand Down Expand Up @@ -226,7 +229,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
if (match(lockhost, host)) {

spin_unlock(&flctx->flc_lock);
if (nlm_unlock_files(file, fl->fl_owner))
if (nlm_unlock_files(file, fl))
return 1;
goto again;
}
Expand Down

0 comments on commit 95d42a8

Please sign in to comment.