Skip to content

Commit 0ef7ef4

Browse files
Julian Suntytso
authored andcommitted
ext4: add missing down_write_data_sem in mext_move_extent().
Commit 962e8a0 ("ext4: introduce mext_move_extent()") attempts to call ext4_swap_extents() on the failure path to recover the swapped extents, but fails to acquire locks for the two inode->i_data_sem, triggering the BUG_ON statement in ext4_swap_extents(). This issue can be fixed by calling ext4_double_down_write_data_sem() before ext4_swap_extents(). Signed-off-by: Julian Sun <sunjunchao@bytedance.com> Reported-by: syzbot+4ea6bd8737669b423aae@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/69368649.a70a0220.38f243.0093.GAE@google.com/ Fixes: 962e8a0 ("ext4: introduce mext_move_extent()") Reviewed-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Zhang Yi <yi.zhang@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Link: https://patch.msgid.link/20251208123713.1971068-1-sunjunchao@bytedance.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent cd16edb commit 0ef7ef4

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/ext4/move_extent.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,11 @@ static int mext_move_extent(struct mext_data *mext, u64 *m_len)
393393

394394
repair_branches:
395395
ret2 = 0;
396+
ext4_double_down_write_data_sem(orig_inode, donor_inode);
396397
r_len = ext4_swap_extents(handle, donor_inode, orig_inode,
397398
mext->donor_lblk, orig_map->m_lblk,
398399
*m_len, 0, &ret2);
400+
ext4_double_up_write_data_sem(orig_inode, donor_inode);
399401
if (ret2 || r_len != *m_len) {
400402
ext4_error_inode_block(orig_inode, (sector_t)(orig_map->m_lblk),
401403
EIO, "Unable to copy data block, data will be lost!");

0 commit comments

Comments
 (0)