Skip to content

Commit

Permalink
locks: close potential race in lease_get_mtime
Browse files Browse the repository at this point in the history
lease_get_mtime is called without the i_lock held, so there's no
guarantee about the stability of the list. Between the time when we
assign "flock" and then dereference it to check whether it's a lease
and for write, the lease could be freed.

Ensure that that doesn't occur by taking the i_lock before trying
to check the lease.

Cc: J. Bruce Fields <bfields@fieldses.org>
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Jeff Layton committed Oct 7, 2014
1 parent e0b93ed commit bfe8602
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1456,8 +1456,18 @@ EXPORT_SYMBOL(__break_lease);
*/
void lease_get_mtime(struct inode *inode, struct timespec *time)
{
struct file_lock *flock = inode->i_flock;
if (flock && IS_LEASE(flock) && (flock->fl_type == F_WRLCK))
bool has_lease = false;
struct file_lock *flock;

if (inode->i_flock) {
spin_lock(&inode->i_lock);
flock = inode->i_flock;
if (flock && IS_LEASE(flock) && (flock->fl_type == F_WRLCK))
has_lease = true;
spin_unlock(&inode->i_lock);
}

if (has_lease)
*time = current_fs_time(inode->i_sb);
else
*time = inode->i_mtime;
Expand Down

0 comments on commit bfe8602

Please sign in to comment.