Skip to contentSkip to conversation

fs: btrfs: Fix wrong comparison in logical to physical mapping

PATCH New Marek Behún 2 participants 2 messages Jul 4, 2018 – Jul 20, 2018 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fs: btrfs: Fix wrong comparison in logical to physical mapping

The comparison
logical > item->logical + item->length
in btrfs_map_logical_to_physical is wrong and should be instead
logical >= item->logical + item->length
For example, if
item->logical = 4096
item->length = 4096
and we are looking for logical = 8192, it is not part of item (item is [4096, 8191]). But the comparison is false and we think we have found the correct item, although we should be searing in the right subtree.

This fixes some bugs I encountered.

---
 fs/btrfs/chunk-map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/chunk-map.c +1 -1
index beb6a4bb92..0c9a659f8f 100644
@@ -78,7 +78,7 @@ u64 btrfs_map_logical_to_physical(u64 logical)
 
 		if (item->logical > logical)
 			node = node->rb_left;
-		else if (logical > item->logical + item->length)
+		else if (logical >= item->logical + item->length)
 			node = node->rb_right;
 		else
 			return item->physical + logical - item->logical;
Signature · 1 line
2.16.4
#1 lore raw

PATCH v2 1/1 fs: btrfs: Fix wrong comparison in logical to physical mapping

Quoted 11 lines · Marek Behún

The comparison
logical > item->logical + item->length
in btrfs_map_logical_to_physical is wrong and should be instead
logical >= item->logical + item->length
For example, if
item->logical = 4096
item->length = 4096
and we are looking for logical = 8192, it is not part of item (item is [4096, 8191]). But the comparison is false and we think we have found the correct item, although we should be searing in the right subtree.

Quoted 3 lines

This fixes some bugs I encountered.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180720/9fe43b4c/attachment.sig>