diff options
author | Filipe Manana <fdmanana@suse.com> | 2020-03-10 15:13:53 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-03-25 10:25:56 +0300 |
commit | eaa7fe20231a4b86ffec5e3521d6efc6d435efe2 (patch) | |
tree | 0d5cccb979b508abb51cd3ccd2c81afc7c6c1662 /fs | |
parent | 039547fbd1e8cc0dcfe3dcb676556a9484dbe360 (diff) | |
download | linux-eaa7fe20231a4b86ffec5e3521d6efc6d435efe2.tar.xz |
btrfs: fix log context list corruption after rename whiteout error
commit 236ebc20d9afc5e9ff52f3cf3f365a91583aac10 upstream.
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 e6c617102c7e4 ("Btrfs: fix log context list
corruption after rename exchange operation") fixed.
Fixes: d4682ba03ef618 ("Btrfs: sync log after logging new name")
CC: stable@vger.kernel.org # 4.19+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/inode.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c056d12cbb3c..94b0df3fb3c8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -10142,6 +10142,10 @@ out_fail: ret = btrfs_sync_log(trans, BTRFS_I(old_inode)->root, &ctx); if (ret) commit_transaction = true; + } else if (sync_log) { + mutex_lock(&root->log_mutex); + list_del(&ctx.list); + mutex_unlock(&root->log_mutex); } if (commit_transaction) { ret = btrfs_commit_transaction(trans); |