btrfs: fix incorrect return value after crossing leaf boundary in lookup_extent_data_ref
PATCH 1/1 btrfs: fix incorrect return value after crossing leaf boundary in lookup_extent_data_ref
After commit 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()"), the err and ret variables were merged into a single ret variable. However, when btrfs_next_leaf() returns 0 (success), ret is overwritten from -ENOENT to 0. If the first key in the next leaf does not match (different objectid or type), the function returns 0 instead of -ENOENT, making the caller believe the lookup succeeded when it did not. This can lead to operations on the wrong extent tree item, potentially causing extent tree corruption.
Fix this by returning -ENOENT directly when the key does not match, instead of relying on the ret variable.
--- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent-tree.c +1 -1
@@ -495,7 +495,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]);if (key.objectid != bytenr || key.type !=BTRFS_EXTENT_DATA_REF_KEY ) -return ret; +return -ENOENT ; ref =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_extent_data_ref);
Signature · 4 lines
2.43.0 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Quoted 10 lines · robbieko
After commit
1618aa3c2e01("btrfs: simplify return variables inlookup_extent_data_ref()"), the err and ret variables were merged into a single ret variable. However, whenbtrfs_next_leaf()returns 0 (success), ret is overwritten from-ENOENTto 0. If the first key in the next leaf does not match (different objectid or type), the function returns 0 instead of-ENOENT, making the caller believe the lookup succeeded when it did not. This can lead to operations on the wrong extent tree item, potentially causing extent tree corruption.
Quoted 5 lines
Fix this by returning
-ENOENTdirectly when the key does not match, instead of relying on the ret variable.Fixes 1618aa3c2e01 ("btrfs: simplify return variables in lookup_extent_data_ref()")Signed-off-by robbieko <[email protected]>
Looks good, thanks.
Quoted 23 lines
--- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/btrfs/extent-tree.c +1
-2@@ -495,7 +495,7 @@ static noinline int lookup_extent_data_ref(struct btrfs_trans_handle *trans,btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]);if (key.objectid != bytenr || key.type !=BTRFS_EXTENT_DATA_REF_KEY ) -return ret; +return -ENOENT ; ref =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_extent_data_ref); --2.43.0
Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.