]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: fix unexpected error path when reflinking an inline extent
authorFilipe Manana <fdmanana@suse.com>
Thu, 17 Feb 2022 12:12:07 +0000 (12:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:40 +0000 (13:57 +0200)
commit783ab5b8e289ebf4b3404ea94de90e63a5c1354e
treec1909ef35aef1454b5702f42d3a1a769e7235fae
parent06f6c6fc8355fe9f1c1ef2077200f2d4c23a2176
btrfs: fix unexpected error path when reflinking an inline extent

[ Upstream commit 1f4613cdbe7739ce291554b316bff8e551383389 ]

When reflinking an inline extent, we assert that its file offset is 0 and
that its uncompressed length is not greater than the sector size. We then
return an error if one of those conditions is not satisfied. However we
use a return statement, which results in returning from btrfs_clone()
without freeing the path and buffer that were allocated before, as well as
not clearing the flag BTRFS_INODE_NO_DELALLOC_FLUSH for the destination
inode.

Fix that by jumping to the 'out' label instead, and also add a WARN_ON()
for each condition so that in case assertions are disabled, we get to
known which of the unexpected conditions triggered the error.

Fixes: a61e1e0df9f321 ("Btrfs: simplify inline extent handling when doing reflinks")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/reflink.c