Skip to content

Commit 236ebc2

Browse files
fdmananakdave
authored andcommitted
btrfs: fix log context list corruption after rename whiteout error
During a rename whiteout, if btrfs_whiteout_for_rename() returns an error we can end up returning from btrfs_rename() with the log context object still in the root's log context list - this happens if 'sync_log' was set to true before we called btrfs_whiteout_for_rename() and it is dangerous because we end up with a corrupt linked list (root->log_ctxs) as the log context object was allocated on the stack. After btrfs_rename() returns, any task that is running btrfs_sync_log() concurrently can end up crashing because that linked list is traversed by btrfs_sync_log() (through btrfs_remove_all_log_ctxs()). That results in the same issue that commit e6c6171 ("Btrfs: fix log context list corruption after rename exchange operation") fixed. Fixes: d4682ba ("Btrfs: sync log after logging new name") CC: [email protected] # 4.19+ Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent e7a0489 commit 236ebc2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/btrfs/inode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9496,6 +9496,10 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
94969496
ret = btrfs_sync_log(trans, BTRFS_I(old_inode)->root, &ctx);
94979497
if (ret)
94989498
commit_transaction = true;
9499+
} else if (sync_log) {
9500+
mutex_lock(&root->log_mutex);
9501+
list_del(&ctx.list);
9502+
mutex_unlock(&root->log_mutex);
94999503
}
95009504
if (commit_transaction) {
95019505
ret = btrfs_commit_transaction(trans);

0 commit comments

Comments
 (0)