Skip to content

Commit e69cb57

Browse files
committed
ext4: fix double-free of blocks due to wrong extents moved_len
jira VULN-4781 cve CVE-2024-26704 commit-author Baokun Li <[email protected]> commit 55583e8 In ext4_move_extents(), moved_len is only updated when all moves are successfully executed, and only discards orig_inode and donor_inode preallocations when moved_len is not zero. When the loop fails to exit after successfully moving some extents, moved_len is not updated and remains at 0, so it does not discard the preallocations. If the moved extents overlap with the preallocated extents, the overlapped extents are freed twice in ext4_mb_release_inode_pa() and ext4_process_freed_data() (as described in commit 94d7c16 ("ext4: Fix double-free of blocks with EXT4_IOC_MOVE_EXT")), and bb_free is incremented twice. Hence when trim is executed, a zero-division bug is triggered in mb_update_avg_fragment_size() because bb_free is not zero and bb_fragments is zero. Therefore, update move_len after each extent move to avoid the issue. Reported-by: Wei Chen <[email protected]> Reported-by: xingwei lee <[email protected]> Closes: https://lore.kernel.org/r/CAO4mrferzqBUnCag8R3m2zf897ts9UEuhjFQGPtODT92rYyR2Q@mail.gmail.com Fixes: fcf6b1b ("ext4: refactor ext4_move_extents code base") CC: <[email protected]> # 3.18 Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> (cherry picked from commit 55583e8) Signed-off-by: Anmol Jain <[email protected]>
1 parent faf3a26 commit e69cb57

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

fs/ext4/move_extent.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
615615
goto out;
616616
o_end = o_start + len;
617617

618+
*moved_len = 0;
618619
while (o_start < o_end) {
619620
struct ext4_extent *ex;
620621
ext4_lblk_t cur_blk, next_blk;
@@ -669,7 +670,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
669670
*/
670671
ext4_double_up_write_data_sem(orig_inode, donor_inode);
671672
/* Swap original branches with new branches */
672-
move_extent_per_page(o_filp, donor_inode,
673+
*moved_len += move_extent_per_page(o_filp, donor_inode,
673674
orig_page_index, donor_page_index,
674675
offset_in_page, cur_len,
675676
unwritten, &ret);
@@ -679,9 +680,6 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
679680
o_start += cur_len;
680681
d_start += cur_len;
681682
}
682-
*moved_len = o_start - orig_blk;
683-
if (*moved_len > len)
684-
*moved_len = len;
685683

686684
out:
687685
if (*moved_len) {

0 commit comments

Comments
 (0)