Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 130d1f95 authored by Jeff Layton's avatar Jeff Layton
Browse files

locks: ensure that fl_owner is always initialized properly in flock and lease codepaths



Currently, the fl_owner isn't set for flock locks. Some filesystems use
byte-range locks to simulate flock locks and there is a common idiom in
those that does:

    fl->fl_owner = (fl_owner_t)filp;
    fl->fl_start = 0;
    fl->fl_end = OFFSET_MAX;

Since flock locks are generally "owned" by the open file description,
move this into the common flock lock setup code. The fl_start and fl_end
fields are already set appropriately, so remove the unneeded setting of
that in flock ops in those filesystems as well.

Finally, the lease code also sets the fl_owner as if they were owned by
the process and not the open file description. This is incorrect as
leases have the same ownership semantics as flock locks. Set them the
same way. The lease code doesn't actually use the fl_owner value for
anything, so this is more for consistency's sake than a bugfix.

Reported-by: default avatarTrond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: default avatarJeff Layton <jlayton@poochiereds.net>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (Staging portion)
Acked-by: default avatarJ. Bruce Fields <bfields@fieldses.org>
parent cf01f4ee
Loading
Loading
Loading
Loading
+6 −11
Original line number Original line Diff line number Diff line
@@ -2691,20 +2691,15 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)


	ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FLOCK, 1);
	ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_FLOCK, 1);


	if (file_lock->fl_flags & FL_FLOCK) {
	if (file_lock->fl_flags & FL_FLOCK)
		LASSERT((cmd == F_SETLKW) || (cmd == F_SETLK));
		LASSERT((cmd == F_SETLKW) || (cmd == F_SETLK));
		/* flocks are whole-file locks */
	else if (!(file_lock->fl_flags & FL_POSIX))
		flock.l_flock.end = OFFSET_MAX;
		return -EINVAL;
		/* For flocks owner is determined by the local file descriptor*/

		flock.l_flock.owner = (unsigned long)file_lock->fl_file;
	} else if (file_lock->fl_flags & FL_POSIX) {
	flock.l_flock.owner = (unsigned long)file_lock->fl_owner;
	flock.l_flock.owner = (unsigned long)file_lock->fl_owner;
	flock.l_flock.pid = file_lock->fl_pid;
	flock.l_flock.start = file_lock->fl_start;
	flock.l_flock.start = file_lock->fl_start;
	flock.l_flock.end = file_lock->fl_end;
	flock.l_flock.end = file_lock->fl_end;
	} else {
		return -EINVAL;
	}
	flock.l_flock.pid = file_lock->fl_pid;


	/* Somewhat ugly workaround for svc lockd.
	/* Somewhat ugly workaround for svc lockd.
	 * lockd installs custom fl_lmops->lm_compare_owner that checks
	 * lockd installs custom fl_lmops->lm_compare_owner that checks
+0 −3
Original line number Original line Diff line number Diff line
@@ -352,9 +352,6 @@ static int v9fs_file_flock_dotl(struct file *filp, int cmd,
		invalidate_mapping_pages(&inode->i_data, 0, -1);
		invalidate_mapping_pages(&inode->i_data, 0, -1);
	}
	}
	/* Convert flock to posix lock */
	/* Convert flock to posix lock */
	fl->fl_owner = (fl_owner_t)filp;
	fl->fl_start = 0;
	fl->fl_end = OFFSET_MAX;
	fl->fl_flags |= FL_POSIX;
	fl->fl_flags |= FL_POSIX;
	fl->fl_flags ^= FL_FLOCK;
	fl->fl_flags ^= FL_FLOCK;


+0 −4
Original line number Original line Diff line number Diff line
@@ -555,10 +555,6 @@ int afs_flock(struct file *file, int cmd, struct file_lock *fl)
		return -ENOLCK;
		return -ENOLCK;


	/* we're simulating flock() locks using posix locks on the server */
	/* we're simulating flock() locks using posix locks on the server */
	fl->fl_owner = (fl_owner_t) file;
	fl->fl_start = 0;
	fl->fl_end = OFFSET_MAX;

	if (fl->fl_type == F_UNLCK)
	if (fl->fl_type == F_UNLCK)
		return afs_do_unlk(file, fl);
		return afs_do_unlk(file, fl);
	return afs_do_setlk(file, fl);
	return afs_do_setlk(file, fl);
+2 −8
Original line number Original line Diff line number Diff line
@@ -53,10 +53,7 @@ static int ceph_lock_message(u8 lock_type, u16 operation, struct file *file,
	else
	else
		length = fl->fl_end - fl->fl_start + 1;
		length = fl->fl_end - fl->fl_start + 1;


	if (lock_type == CEPH_LOCK_FCNTL)
	owner = secure_addr(fl->fl_owner);
	owner = secure_addr(fl->fl_owner);
	else
		owner = secure_addr(fl->fl_file);


	dout("ceph_lock_message: rule: %d, op: %d, owner: %llx, pid: %llu, "
	dout("ceph_lock_message: rule: %d, op: %d, owner: %llx, pid: %llu, "
	     "start: %llu, length: %llu, wait: %d, type: %d", (int)lock_type,
	     "start: %llu, length: %llu, wait: %d, type: %d", (int)lock_type,
@@ -314,10 +311,7 @@ int lock_to_ceph_filelock(struct file_lock *lock,
	cephlock->length = cpu_to_le64(lock->fl_end - lock->fl_start + 1);
	cephlock->length = cpu_to_le64(lock->fl_end - lock->fl_start + 1);
	cephlock->client = cpu_to_le64(0);
	cephlock->client = cpu_to_le64(0);
	cephlock->pid = cpu_to_le64((u64)lock->fl_pid);
	cephlock->pid = cpu_to_le64((u64)lock->fl_pid);
	if (lock->fl_flags & FL_POSIX)
	cephlock->owner = cpu_to_le64(secure_addr(lock->fl_owner));
	cephlock->owner = cpu_to_le64(secure_addr(lock->fl_owner));
	else
		cephlock->owner = cpu_to_le64(secure_addr(lock->fl_file));


	switch (lock->fl_type) {
	switch (lock->fl_type) {
	case F_RDLCK:
	case F_RDLCK:
+0 −1
Original line number Original line Diff line number Diff line
@@ -2304,7 +2304,6 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
		struct fuse_file *ff = file->private_data;
		struct fuse_file *ff = file->private_data;


		/* emulate flock with POSIX locks */
		/* emulate flock with POSIX locks */
		fl->fl_owner = (fl_owner_t) file;
		ff->flock = true;
		ff->flock = true;
		err = fuse_setlk(file, fl, 1);
		err = fuse_setlk(file, fl, 1);
	}
	}
Loading