Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

btrfs: fix uninitialized return value in the ref-verify tool

In the ref-verify tool, when processing the inline references of an extent
item, we may end up returning with uninitialized return value, because:

1) The 'ret' variable is not initialized if there are no inline extent
references ('ptr' == 'end' before the while loop starts);

2) If we find an extent owner inline reference we don't initialize 'ret'.

So fix these cases by initializing 'ret' to 0 when declaring the variable
and set it to -EINVAL if we find an extent owner inline references and
simple quotas are not enabled (as well as print an error message).

Reported-by: Mirsad Todorovac <mtodorovac69@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/59b40ebe-c824-457d-8b24-0bbca69d472b@gmail.com/
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Filipe Manana and committed by
David Sterba
9da45c88 724d8042

+7 -2
+7 -2
fs/btrfs/ref-verify.c
··· 441 441 u32 item_size = btrfs_item_size(leaf, slot); 442 442 unsigned long end, ptr; 443 443 u64 offset, flags, count; 444 - int type, ret; 444 + int type; 445 + int ret = 0; 445 446 446 447 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); 447 448 flags = btrfs_extent_flags(leaf, ei); ··· 487 486 key->objectid, key->offset); 488 487 break; 489 488 case BTRFS_EXTENT_OWNER_REF_KEY: 490 - WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA)); 489 + if (!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA)) { 490 + btrfs_err(fs_info, 491 + "found extent owner ref without simple quotas enabled"); 492 + ret = -EINVAL; 493 + } 491 494 break; 492 495 default: 493 496 btrfs_err(fs_info, "invalid key type in iref");