fs/hfsplus/extents.c: fix concurrent acess of alloc_blocks

Concurrent access to alloc_blocks in hfsplus_inode_info() is protected
by extents_lock mutex.  This patch fixes two instances where
alloc_blocks modification was not protected with this lock.

This fixes possible allocation bitmap corruption in race conditions
while extending and truncating files.

[[email protected]: take extents_lock before taking a copy of ->alloc_blocks]
[[email protected]: remove now-unused label `out']
Signed-off-by: Sougata Santra <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Cc: Vyacheslav Dubeyko <[email protected]>
Cc: Alexey Khoroshilov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Sougata Santra 2014-04-03 14:50:34 -07:00 • committed by Linus Torvalds
commit d7bdb996ae

View file

@ -496,11 +496,13 @@ int hfsplus_file_extend(struct inode *inode)
goto insert_extent;
}
out:
mutex_unlock(&hip->extents_lock);
if (!res) {
hip->alloc_blocks += len;
mutex_unlock(&hip->extents_lock);
hfsplus_mark_inode_dirty(inode, HFSPLUS_I_ALLOC_DIRTY);
return 0;
}
mutex_unlock(&hip->extents_lock);
return res;
insert_extent:
@ -554,11 +556,13 @@ void hfsplus_file_truncate(struct inode *inode)
blk_cnt = (inode->i_size + HFSPLUS_SB(sb)->alloc_blksz - 1) >>
HFSPLUS_SB(sb)->alloc_blksz_shift;
alloc_cnt = hip->alloc_blocks;
if (blk_cnt == alloc_cnt)
goto out;
mutex_lock(&hip->extents_lock);
alloc_cnt = hip->alloc_blocks;
if (blk_cnt == alloc_cnt)
goto out_unlock;
res = hfs_find_init(HFSPLUS_SB(sb)->ext_tree, &fd);
if (res) {
mutex_unlock(&hip->extents_lock);
@ -590,10 +594,10 @@ void hfsplus_file_truncate(struct inode *inode)
hfs_brec_remove(&fd);
}
hfs_find_exit(&fd);
mutex_unlock(&hip->extents_lock);
hip->alloc_blocks = blk_cnt;
out:
out_unlock:
mutex_unlock(&hip->extents_lock);
hip->phys_size = inode->i_size;
hip->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >>
sb->s_blocksize_bits;