diff options
author | Jeff Layton <jlayton@primarydata.com> | 2014-08-22 10:18:44 -0400 |
---|---|---|
committer | Jeff Layton <jlayton@primarydata.com> | 2014-10-07 14:06:12 -0400 |
commit | bfe8602436c803c6d5e271d52cd985d491a7470a (patch) | |
tree | 17b28bd50fd22ae65f90e9bd09cc5b14415a0049 /fs/locks.c | |
parent | e0b93eddfe17dcb7d644eb5d6ad02a86fc41a977 (diff) |
locks: close potential race in lease_get_mtime
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>
Diffstat (limited to 'fs/locks.c')
-rw-r--r-- | fs/locks.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/fs/locks.c b/fs/locks.c index f5f648e003dd..def1ac2e87bd 100644 --- a/fs/locks.c +++ b/fs/locks.c | |||
@@ -1456,8 +1456,18 @@ EXPORT_SYMBOL(__break_lease); | |||
1456 | */ | 1456 | */ |
1457 | void lease_get_mtime(struct inode *inode, struct timespec *time) | 1457 | void lease_get_mtime(struct inode *inode, struct timespec *time) |
1458 | { | 1458 | { |
1459 | struct file_lock *flock = inode->i_flock; | 1459 | bool has_lease = false; |
1460 | if (flock && IS_LEASE(flock) && (flock->fl_type == F_WRLCK)) | 1460 | struct file_lock *flock; |
1461 | |||
1462 | if (inode->i_flock) { | ||
1463 | spin_lock(&inode->i_lock); | ||
1464 | flock = inode->i_flock; | ||
1465 | if (flock && IS_LEASE(flock) && (flock->fl_type == F_WRLCK)) | ||
1466 | has_lease = true; | ||
1467 | spin_unlock(&inode->i_lock); | ||
1468 | } | ||
1469 | |||
1470 | if (has_lease) | ||
1461 | *time = current_fs_time(inode->i_sb); | 1471 | *time = current_fs_time(inode->i_sb); |
1462 | else | 1472 | else |
1463 | *time = inode->i_mtime; | 1473 | *time = inode->i_mtime; |