This is a note to let you know that I've just added the patch titled btrfs: add missing error handling when logging operation while COWing extent buffer to the 6.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-add-missing-error-handling-when-logging-operation-while-cowing-extent-buffer.patch and it can be found in the queue-6.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From d09c51521f22f9cbdfb1cf63e5c456077c622c84 Mon Sep 17 00:00:00 2001 From: Filipe Manana <fdmanana@xxxxxxxx> Date: Thu, 8 Jun 2023 11:27:37 +0100 Subject: btrfs: add missing error handling when logging operation while COWing extent buffer From: Filipe Manana <fdmanana@xxxxxxxx> commit d09c51521f22f9cbdfb1cf63e5c456077c622c84 upstream. When COWing an extent buffer that is not the root node, we need to log in the tree mod log that we replaced a pointer in the parent node, otherwise a tree mod log user doing a search on the b+tree can return incorrect results (that miss something). We are doing the call to btrfs_tree_mod_log_insert_key() but we totally ignore its return value. So fix this by adding the missing error handling, resulting in a transaction abort and freeing the COWed extent buffer. Fixes: f230475e62f7 ("Btrfs: put all block modifications into the tree mod log") CC: stable@xxxxxxxxxxxxxxx # 5.4+ Reviewed-by: Qu Wenruo <wqu@xxxxxxxx> Signed-off-by: Filipe Manana <fdmanana@xxxxxxxx> Reviewed-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/ctree.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -594,8 +594,14 @@ static noinline int __btrfs_cow_block(st add_root_to_dirty_list(root); } else { WARN_ON(trans->transid != btrfs_header_generation(parent)); - btrfs_tree_mod_log_insert_key(parent, parent_slot, - BTRFS_MOD_LOG_KEY_REPLACE); + ret = btrfs_tree_mod_log_insert_key(parent, parent_slot, + BTRFS_MOD_LOG_KEY_REPLACE); + if (ret) { + btrfs_tree_unlock(cow); + free_extent_buffer(cow); + btrfs_abort_transaction(trans, ret); + return ret; + } btrfs_set_node_blockptr(parent, parent_slot, cow->start); btrfs_set_node_ptr_generation(parent, parent_slot, Patches currently in stable-queue which might be from fdmanana@xxxxxxxx are queue-6.4/btrfs-bail-out-reclaim-process-if-filesystem-is-read-only.patch queue-6.4/btrfs-warn-on-invalid-slot-in-tree-mod-log-rewind.patch queue-6.4/btrfs-add-missing-error-handling-when-logging-operation-while-cowing-extent-buffer.patch queue-6.4/btrfs-fix-extent-buffer-leak-after-tree-mod-log-failure-at-split_node.patch queue-6.4/btrfs-fix-race-when-deleting-free-space-root-from-the-dirty-cow-roots-list.patch queue-6.4/btrfs-move-out-now-unused-bg-from-the-reclaim-list.patch queue-6.4/btrfs-fix-race-when-deleting-quota-root-from-the-dirty-cow-roots-list.patch queue-6.4/btrfs-delete-unused-bgs-while-reclaiming-bgs.patch queue-6.4/btrfs-do-not-bug_on-on-tree-mod-log-failure-at-balance_level.patch queue-6.4/btrfs-do-not-bug_on-on-tree-mod-log-failure-at-__btrfs_cow_block.patch queue-6.4/btrfs-insert-tree-mod-log-move-in-push_node_left.patch