Commit 57073d34 authored by Jan Kara's avatar Jan Kara Committed by Greg Kroah-Hartman

ext3: Fix oops in ext3_try_to_allocate_with_rsv()

commit ad95c5e9 upstream.

Block allocation is called from two places: ext3_get_blocks_handle() and
ext3_xattr_block_set(). These two callers are not necessarily synchronized
because xattr code holds only xattr_sem and i_mutex, and
ext3_get_blocks_handle() may hold only truncate_mutex when called from
writepage() path. Block reservation code does not expect two concurrent
allocations to happen to the same inode and thus assertions can be triggered
or reservation structure corruption can occur.

Fix the problem by taking truncate_mutex in xattr code to serialize
allocations.

CC: Sage Weil <sage@newdream.net>
Reported-by: default avatarFyodor Ustinov <ufm@ufm.su>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent fac04f94
...@@ -803,8 +803,16 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode, ...@@ -803,8 +803,16 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
/* We need to allocate a new block */ /* We need to allocate a new block */
ext3_fsblk_t goal = ext3_group_first_block_no(sb, ext3_fsblk_t goal = ext3_group_first_block_no(sb,
EXT3_I(inode)->i_block_group); EXT3_I(inode)->i_block_group);
ext3_fsblk_t block = ext3_new_block(handle, inode, ext3_fsblk_t block;
goal, &error);
/*
* Protect us agaist concurrent allocations to the
* same inode from ext3_..._writepage(). Reservation
* code does not expect racing allocations.
*/
mutex_lock(&EXT3_I(inode)->truncate_mutex);
block = ext3_new_block(handle, inode, goal, &error);
mutex_unlock(&EXT3_I(inode)->truncate_mutex);
if (error) if (error)
goto cleanup; goto cleanup;
ea_idebug(inode, "creating block %d", block); ea_idebug(inode, "creating block %d", block);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment