]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: fix off-by-one chunk length calculation at contains_pending_extent()
authorFilipe Manana <fdmanana@suse.com>
Thu, 29 Feb 2024 10:37:04 +0000 (10:37 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 5 Mar 2024 17:11:07 +0000 (18:11 +0100)
At contains_pending_extent() the value of the end offset of a chunk we
found in the device's allocation state io tree is inclusive, so when
we calculate the length we pass to the in_range() macro, we must sum
1 to the expression "physical_end - physical_offset".

In practice the wrong calculation should be harmless as chunks sizes
are never 1 byte and we should never have 1 byte ranges of unallocated
space. Nevertheless fix the wrong calculation.

Reported-by: Alex Lyakas <alex.lyakas@zadara.com>
Link: https://lore.kernel.org/linux-btrfs/CAOcd+r30e-f4R-5x-S7sV22RJPe7+pgwherA6xqN2_qe7o4XTg@mail.gmail.com/
Fixes: 1c11b63eff2a ("btrfs: replace pending/pinned chunks lists with io tree")
CC: stable@vger.kernel.org # 6.1+
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/volumes.c

index 5239b76775ba47ab9f43e113085fae16f019323e..e49935a54da0a398a672ac4c79d2e007a532a913 100644 (file)
@@ -1406,7 +1406,7 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
 
                if (in_range(physical_start, *start, len) ||
                    in_range(*start, physical_start,
-                            physical_end - physical_start)) {
+                            physical_end + 1 - physical_start)) {
                        *start = physical_end + 1;
                        return true;
                }