Skip to content

Commit f4f5bd9

Browse files
fdmananagregkh
authored andcommitted
btrfs: abort transaction on unexpected eb generation at btrfs_copy_root()
[ Upstream commit 33e8f24 ] If we find an unexpected generation for the extent buffer we are cloning at btrfs_copy_root(), we just WARN_ON() and don't error out and abort the transaction, meaning we allow to persist metadata with an unexpected generation. Instead of warning only, abort the transaction and return -EUCLEAN. CC: stable@vger.kernel.org # 6.1+ Reviewed-by: Daniel Vacek <neelx@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 31faf31 commit f4f5bd9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

fs/btrfs/ctree.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,14 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
283283

284284
write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
285285

286-
WARN_ON(btrfs_header_generation(buf) > trans->transid);
286+
if (unlikely(btrfs_header_generation(buf) > trans->transid)) {
287+
btrfs_tree_unlock(cow);
288+
free_extent_buffer(cow);
289+
ret = -EUCLEAN;
290+
btrfs_abort_transaction(trans, ret);
291+
return ret;
292+
}
293+
287294
if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
288295
ret = btrfs_inc_ref(trans, root, cow, 1);
289296
else

0 commit comments

Comments
 (0)