btrfs: fix wrong file range cleanup after an error filling dealloc range
authorFilipe Manana <fdmanana@suse.com>
Wed, 27 May 2020 10:15:53 +0000 (11:15 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 22 Jun 2020 07:31:13 +0000 (09:31 +0200)
commit8076bdd4fe0053454a1b80ca0476b6c6f5c87375
tree520b2d21a9ddc985e8fd9602ba42b55186a3b82f
parentc2c69ecb605f7a8983ddbb50cc6829c4f2e7c2a3
btrfs: fix wrong file range cleanup after an error filling dealloc range

commit e2c8e92d1140754073ad3799eb6620c76bab2078 upstream.

If an error happens while running dellaloc in COW mode for a range, we can
end up calling extent_clear_unlock_delalloc() for a range that goes beyond
our range's end offset by 1 byte, which affects 1 extra page. This results
in clearing bits and doing page operations (such as a page unlock) outside
our target range.

Fix that by calling extent_clear_unlock_delalloc() with an inclusive end
offset, instead of an exclusive end offset, at cow_file_range().

Fixes: a315e68f6e8b30 ("Btrfs: fix invalid attempt to free reserved space on failure to cow range")
CC: stable@vger.kernel.org # 4.14+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/inode.c