]> git.baikalelectronics.ru Git - kernel.git/commit
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, 14 Mar 2022 12:13:52 +0000 (13:13 +0100)
commit619faec7a2f51d178d1d48f405d5dd8ef3862c6c
treeefd6108e74d75282bc465756bea8d501f615eeb8
parent68214fa02098c6357984105ab42b618187b434c4
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