Skip to content

Commit 08eabe4

Browse files
ivpravdinakpm00
authored andcommitted
ocfs2: avoid potential ABBA deadlock by reordering tl_inode lock
In ocfs2_move_extent(), tl_inode is currently locked after the global bitmap inode. However, in ocfs2_flush_truncate_log(), the lock order is reversed: tl_inode is locked first, followed by the global bitmap inode. This creates a classic ABBA deadlock scenario if two threads attempt these operations concurrently and acquire the locks in different orders. To prevent this, move the tl_inode locking earlier in ocfs2_move_extent(), so that it always precedes the global bitmap inode lock. No functional changes beyond lock ordering. Link: https://lkml.kernel.org/r/20250708020640.387741-1-ipravdin.official@gmail.com Reported-by: syzbot+6bf948e47f9bac7aacfa@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/67d5645c.050a0220.1dc86f.0004.GAE@google.com/ Signed-off-by: Ivan Pravdin <ipravdin.official@gmail.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 97103dc commit 08eabe4

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

fs/ocfs2/move_extents.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
617617
*/
618618
credits += OCFS2_INODE_UPDATE_CREDITS + 1;
619619

620+
inode_lock(tl_inode);
621+
620622
/*
621623
* ocfs2_move_extent() didn't reserve any clusters in lock_allocators()
622624
* logic, while we still need to lock the global_bitmap.
@@ -626,24 +628,22 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
626628
if (!gb_inode) {
627629
mlog(ML_ERROR, "unable to get global_bitmap inode\n");
628630
ret = -EIO;
629-
goto out;
631+
goto out_unlock_tl_inode;
630632
}
631633

632634
inode_lock(gb_inode);
633635

634636
ret = ocfs2_inode_lock(gb_inode, &gb_bh, 1);
635637
if (ret) {
636638
mlog_errno(ret);
637-
goto out_unlock_gb_mutex;
639+
goto out_unlock_gb_inode;
638640
}
639641

640-
inode_lock(tl_inode);
641-
642642
handle = ocfs2_start_trans(osb, credits);
643643
if (IS_ERR(handle)) {
644644
ret = PTR_ERR(handle);
645645
mlog_errno(ret);
646-
goto out_unlock_tl_inode;
646+
goto out_unlock;
647647
}
648648

649649
new_phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, *new_phys_cpos);
@@ -703,15 +703,14 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context,
703703
out_commit:
704704
ocfs2_commit_trans(osb, handle);
705705
brelse(gd_bh);
706-
707-
out_unlock_tl_inode:
708-
inode_unlock(tl_inode);
709-
706+
out_unlock:
710707
ocfs2_inode_unlock(gb_inode, 1);
711-
out_unlock_gb_mutex:
708+
out_unlock_gb_inode:
712709
inode_unlock(gb_inode);
713710
brelse(gb_bh);
714711
iput(gb_inode);
712+
out_unlock_tl_inode:
713+
inode_unlock(tl_inode);
715714

716715
out:
717716
if (context->meta_ac) {

0 commit comments

Comments
 (0)