Skip to content

Commit 1fd95c0

Browse files
committed
ext4: add error checking to ext4_ext_replay_set_iblocks()
If the call to ext4_map_blocks() fails due to an corrupted file system, ext4_ext_replay_set_iblocks() can get stuck in an infinite loop. This could be reproduced by running generic/526 with a file system that has inline_data and fast_commit enabled. The system will repeatedly log to the console: EXT4-fs warning (device dm-3): ext4_block_to_path:105: block 1074800922 > max in inode 131076 and the stack that it gets stuck in is: ext4_block_to_path+0xe3/0x130 ext4_ind_map_blocks+0x93/0x690 ext4_map_blocks+0x100/0x660 skip_hole+0x47/0x70 ext4_ext_replay_set_iblocks+0x223/0x440 ext4_fc_replay_inode+0x29e/0x3b0 ext4_fc_replay+0x278/0x550 do_one_pass+0x646/0xc10 jbd2_journal_recover+0x14a/0x270 jbd2_journal_load+0xc4/0x150 ext4_load_journal+0x1f3/0x490 ext4_fill_super+0x22d4/0x2c00 With this patch, generic/526 still fails, but system is no longer locking up in a tight loop. It's likely the root casue is that fast_commit replay is corrupting file systems with inline_data, and we probably need to add better error handling in the fast commit replay code path beyond what is done here, which essentially just breaks the infinite loop without reporting the to the higher levels of the code. Fixes: 8016E29F4362 ("ext4: fast commit recovery path") Cc: [email protected] Cc: Harshad Shirwadkar <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent baaae97 commit 1fd95c0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

fs/ext4/extents.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,7 +5913,7 @@ void ext4_ext_replay_shrink_inode(struct inode *inode, ext4_lblk_t end)
59135913
}
59145914

59155915
/* Check if *cur is a hole and if it is, skip it */
5916-
static void skip_hole(struct inode *inode, ext4_lblk_t *cur)
5916+
static int skip_hole(struct inode *inode, ext4_lblk_t *cur)
59175917
{
59185918
int ret;
59195919
struct ext4_map_blocks map;
@@ -5922,9 +5922,12 @@ static void skip_hole(struct inode *inode, ext4_lblk_t *cur)
59225922
map.m_len = ((inode->i_size) >> inode->i_sb->s_blocksize_bits) - *cur;
59235923

59245924
ret = ext4_map_blocks(NULL, inode, &map, 0);
5925+
if (ret < 0)
5926+
return ret;
59255927
if (ret != 0)
5926-
return;
5928+
return 0;
59275929
*cur = *cur + map.m_len;
5930+
return 0;
59285931
}
59295932

59305933
/* Count number of blocks used by this inode and update i_blocks */
@@ -5973,7 +5976,9 @@ int ext4_ext_replay_set_iblocks(struct inode *inode)
59735976
* iblocks by total number of differences found.
59745977
*/
59755978
cur = 0;
5976-
skip_hole(inode, &cur);
5979+
ret = skip_hole(inode, &cur);
5980+
if (ret < 0)
5981+
goto out;
59775982
path = ext4_find_extent(inode, cur, NULL, 0);
59785983
if (IS_ERR(path))
59795984
goto out;
@@ -5992,8 +5997,12 @@ int ext4_ext_replay_set_iblocks(struct inode *inode)
59925997
}
59935998
cur = max(cur + 1, le32_to_cpu(ex->ee_block) +
59945999
ext4_ext_get_actual_len(ex));
5995-
skip_hole(inode, &cur);
5996-
6000+
ret = skip_hole(inode, &cur);
6001+
if (ret < 0) {
6002+
ext4_ext_drop_refs(path);
6003+
kfree(path);
6004+
break;
6005+
}
59976006
path2 = ext4_find_extent(inode, cur, NULL, 0);
59986007
if (IS_ERR(path2)) {
59996008
ext4_ext_drop_refs(path);

0 commit comments

Comments
 (0)