btrfs: deal with unexpected extent type during reflinking
authorFilipe Manana <fdmanana@suse.com>
Thu, 17 Feb 2022 12:12:08 +0000 (12:12 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 Feb 2022 15:20:04 +0000 (16:20 +0100)
commit38e49db9d286b867951462efa96267b4b69aebe7
treecc15e5699614ed05478ffff8837ca6d9b8364e2f
parentd728f79195013f93d2f9bd056c1f12d0f2c79607
btrfs: deal with unexpected extent type during reflinking

Smatch complains about a possible dereference of a pointer that was not
initialized:

    CC [M]  fs/btrfs/reflink.o
    CHECK   fs/btrfs/reflink.c
  fs/btrfs/reflink.c:533 btrfs_clone() error: potentially dereferencing uninitialized 'trans'.

This is because we are not dealing with the case where the type of a file
extent has an unexpected value (not regular, not prealloc and not inline),
in which case the transaction handle pointer is not initialized.

Such unexpected type should be impossible, except in case of some memory
corruption caused either by bad hardware or some software bug causing
something like a buffer overrun.

So ASSERT that if the extent type is neither regular nor prealloc, then
it must be inline. Bail out with -EUCLEAN and a warning in case it is
not. This silences smatch.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/reflink.c