Skip to content

Commit 5fba5a5

Browse files
fdmananakdave
authored andcommitted
btrfs: fix off-by-one when checking chunk map includes logical address
At btrfs_get_chunk_map() we get the extent map for the chunk that contains the given logical address stored in the 'logical' argument. Then we do sanity checks to verify the extent map contains the logical address. One of these checks verifies if the extent map covers a range with an end offset behind the target logical address - however this check has an off-by-one error since it will consider an extent map whose start offset plus its length matches the target logical address as inclusive, while the fact is that the last byte it covers is behind the target logical address (by 1). So fix this condition by using '<=' rather than '<' when comparing the extent map's "start + length" against the target logical address. CC: stable@vger.kernel.org # 4.14+ Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent f91192c commit 5fba5a5

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3008,7 +3008,7 @@ struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
30083008
return ERR_PTR(-EINVAL);
30093009
}
30103010

3011-
if (em->start > logical || em->start + em->len < logical) {
3011+
if (em->start > logical || em->start + em->len <= logical) {
30123012
btrfs_crit(fs_info,
30133013
"found a bad mapping, wanted %llu-%llu, found %llu-%llu",
30143014
logical, length, em->start, em->start + em->len);

0 commit comments

Comments
 (0)