diff options
author | Sougata Santra <sougata@tuxera.com> | 2014-04-03 17:50:34 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-04-03 19:21:26 -0400 |
commit | d7bdb996aef67ea24c62707ca4e29b07025e9683 (patch) | |
tree | 619189c603f5ff8dca0f83880bc38382da61039d /fs/hfsplus/extents.c | |
parent | abfeb724b43f371ea70ec2c1290ed33e6f65db60 (diff) |
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.
[akpm@linux-foundation.org: take extents_lock before taking a copy of ->alloc_blocks]
[akpm@linux-foundation.org: remove now-unused label `out']
Signed-off-by: Sougata Santra <sougata@tuxera.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Vyacheslav Dubeyko <slava@dubeyko.com>
Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hfsplus/extents.c')
-rw-r--r-- | fs/hfsplus/extents.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c index 136d860cd746..a7aafb35b624 100644 --- a/fs/hfsplus/extents.c +++ b/fs/hfsplus/extents.c | |||
@@ -496,11 +496,13 @@ int hfsplus_file_extend(struct inode *inode) | |||
496 | goto insert_extent; | 496 | goto insert_extent; |
497 | } | 497 | } |
498 | out: | 498 | out: |
499 | mutex_unlock(&hip->extents_lock); | ||
500 | if (!res) { | 499 | if (!res) { |
501 | hip->alloc_blocks += len; | 500 | hip->alloc_blocks += len; |
501 | mutex_unlock(&hip->extents_lock); | ||
502 | hfsplus_mark_inode_dirty(inode, HFSPLUS_I_ALLOC_DIRTY); | 502 | hfsplus_mark_inode_dirty(inode, HFSPLUS_I_ALLOC_DIRTY); |
503 | return 0; | ||
503 | } | 504 | } |
505 | mutex_unlock(&hip->extents_lock); | ||
504 | return res; | 506 | return res; |
505 | 507 | ||
506 | insert_extent: | 508 | insert_extent: |
@@ -554,11 +556,13 @@ void hfsplus_file_truncate(struct inode *inode) | |||
554 | 556 | ||
555 | blk_cnt = (inode->i_size + HFSPLUS_SB(sb)->alloc_blksz - 1) >> | 557 | blk_cnt = (inode->i_size + HFSPLUS_SB(sb)->alloc_blksz - 1) >> |
556 | HFSPLUS_SB(sb)->alloc_blksz_shift; | 558 | HFSPLUS_SB(sb)->alloc_blksz_shift; |
559 | |||
560 | mutex_lock(&hip->extents_lock); | ||
561 | |||
557 | alloc_cnt = hip->alloc_blocks; | 562 | alloc_cnt = hip->alloc_blocks; |
558 | if (blk_cnt == alloc_cnt) | 563 | if (blk_cnt == alloc_cnt) |
559 | goto out; | 564 | goto out_unlock; |
560 | 565 | ||
561 | mutex_lock(&hip->extents_lock); | ||
562 | res = hfs_find_init(HFSPLUS_SB(sb)->ext_tree, &fd); | 566 | res = hfs_find_init(HFSPLUS_SB(sb)->ext_tree, &fd); |
563 | if (res) { | 567 | if (res) { |
564 | mutex_unlock(&hip->extents_lock); | 568 | mutex_unlock(&hip->extents_lock); |
@@ -590,10 +594,10 @@ void hfsplus_file_truncate(struct inode *inode) | |||
590 | hfs_brec_remove(&fd); | 594 | hfs_brec_remove(&fd); |
591 | } | 595 | } |
592 | hfs_find_exit(&fd); | 596 | hfs_find_exit(&fd); |
593 | mutex_unlock(&hip->extents_lock); | ||
594 | 597 | ||
595 | hip->alloc_blocks = blk_cnt; | 598 | hip->alloc_blocks = blk_cnt; |
596 | out: | 599 | out_unlock: |
600 | mutex_unlock(&hip->extents_lock); | ||
597 | hip->phys_size = inode->i_size; | 601 | hip->phys_size = inode->i_size; |
598 | hip->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> | 602 | hip->fs_blocks = (inode->i_size + sb->s_blocksize - 1) >> |
599 | sb->s_blocksize_bits; | 603 | sb->s_blocksize_bits; |