Skip to content

Commit 3581394

Browse files
committed
ext4: fix double-free of blocks due to wrong extents moved_len
jira VULN-144688 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: Brett Mastbergen <[email protected]>
1 parent 1e2ed2a commit 3581394

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
@@ -621,6 +621,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
621621
goto out;
622622
o_end = o_start + len;
623623

624+
*moved_len = 0;
624625
while (o_start < o_end) {
625626
struct ext4_extent *ex;
626627
ext4_lblk_t cur_blk, next_blk;
@@ -675,7 +676,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
675676
*/
676677
ext4_double_up_write_data_sem(orig_inode, donor_inode);
677678
/* Swap original branches with new branches */
678-
move_extent_per_page(o_filp, donor_inode,
679+
*moved_len += move_extent_per_page(o_filp, donor_inode,
679680
orig_page_index, donor_page_index,
680681
offset_in_page, cur_len,
681682
unwritten, &ret);
@@ -685,9 +686,6 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
685686
o_start += cur_len;
686687
d_start += cur_len;
687688
}
688-
*moved_len = o_start - orig_blk;
689-
if (*moved_len > len)
690-
*moved_len = len;
691689

692690
out:
693691
if (*moved_len) {

0 commit comments

Comments
 (0)