Skip to content

Commit e0556a4

Browse files
fdmananakdave
authored andcommitted
btrfs: abort transaction on item count overflow in __push_leaf_left()
If we try to push an item count from the right leaf that is greater than the number of items in the leaf, we just emit a warning. This should never happen but if it does we get an underflow in the new number of items in the right leaf and chaos follows from it. So replace the warning with proper error handling, by aborting the transaction and returning -EUCLEAN, and proper logging by using btrfs_crit() instead of WARN(), which gives us proper formatting and information about the filesystem. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 74406ba commit e0556a4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/btrfs/ctree.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,9 +3419,13 @@ static noinline int __push_leaf_left(struct btrfs_trans_handle *trans,
34193419
btrfs_set_header_nritems(left, old_left_nritems + push_items);
34203420

34213421
/* fixup right node */
3422-
if (push_items > right_nritems)
3423-
WARN(1, KERN_CRIT "push items %d nr %u\n", push_items,
3424-
right_nritems);
3422+
if (unlikely(push_items > right_nritems)) {
3423+
ret = -EUCLEAN;
3424+
btrfs_abort_transaction(trans, ret);
3425+
btrfs_crit(fs_info, "push items (%d) > right leaf items (%u)",
3426+
push_items, right_nritems);
3427+
goto out;
3428+
}
34253429

34263430
if (push_items < right_nritems) {
34273431
push_space = btrfs_item_offset(right, push_items - 1) -

0 commit comments

Comments
 (0)