Skip to content

Commit 3e8a584

Browse files
LiBaokun96tytso
authored andcommitted
ext4: prevent partial update of the extents path
In ext4_ext_rm_idx() and ext4_ext_correct_indexes(), there is no proper rollback of already executed updates when updating a level of the extents path fails, so we may get an inconsistent extents tree, which may trigger some bad things in errors=continue mode. Hence clear the verified bit of modified extents buffers if the tree fails to be updated in ext4_ext_rm_idx() or ext4_ext_correct_indexes(), which forces the extents buffers to be checked in ext4_valid_extent_entries(), ensuring that the extents tree is consistent. Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com> Link: https://lore.kernel.org/r/20230213080514.535568-3-zhanchengbin1@huawei.com/ Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Tested-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://patch.msgid.link/20240822023545.1994557-3-libaokun@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent edfa71d commit 3e8a584

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

fs/ext4/extents.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,12 +1749,23 @@ static int ext4_ext_correct_indexes(handle_t *handle, struct inode *inode,
17491749
break;
17501750
err = ext4_ext_get_access(handle, inode, path + k);
17511751
if (err)
1752-
break;
1752+
goto clean;
17531753
path[k].p_idx->ei_block = border;
17541754
err = ext4_ext_dirty(handle, inode, path + k);
17551755
if (err)
1756-
break;
1756+
goto clean;
17571757
}
1758+
return 0;
1759+
1760+
clean:
1761+
/*
1762+
* The path[k].p_bh is either unmodified or with no verified bit
1763+
* set (see ext4_ext_get_access()). So just clear the verified bit
1764+
* of the successfully modified extents buffers, which will force
1765+
* these extents to be checked to avoid using inconsistent data.
1766+
*/
1767+
while (++k < depth)
1768+
clear_buffer_verified(path[k].p_bh);
17581769

17591770
return err;
17601771
}
@@ -2312,12 +2323,24 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
23122323
break;
23132324
err = ext4_ext_get_access(handle, inode, path + k);
23142325
if (err)
2315-
break;
2326+
goto clean;
23162327
path[k].p_idx->ei_block = path[k + 1].p_idx->ei_block;
23172328
err = ext4_ext_dirty(handle, inode, path + k);
23182329
if (err)
2319-
break;
2330+
goto clean;
23202331
}
2332+
return 0;
2333+
2334+
clean:
2335+
/*
2336+
* The path[k].p_bh is either unmodified or with no verified bit
2337+
* set (see ext4_ext_get_access()). So just clear the verified bit
2338+
* of the successfully modified extents buffers, which will force
2339+
* these extents to be checked to avoid using inconsistent data.
2340+
*/
2341+
while (++k < depth)
2342+
clear_buffer_verified(path[k].p_bh);
2343+
23212344
return err;
23222345
}
23232346

0 commit comments

Comments
 (0)