]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: handle invalid extent item reference found in extent_from_logical()
authorDavid Sterba <dsterba@suse.com>
Wed, 24 Jan 2024 21:41:01 +0000 (22:41 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Mar 2024 15:24:50 +0000 (16:24 +0100)
The extent_from_logical() helper looks up an extent item by a key,
allowing to do an inexact search when key->offset is -1.  It's never
expected to find such item, as it would break the allowed range of a
extent item offset.

The same error is already handled in btrfs_backref_iter_start() so add a
comment for consistency.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c

index 0fa27ed802f6fb1819ce42e37b16f2de2873c109..6ba743ddfe211c2cf04e94f4c5ac446b125cb121 100644 (file)
@@ -2227,6 +2227,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
        ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
        if (ret < 0)
                return ret;
+       if (ret == 0) {
+               /*
+                * Key with offset -1 found, there would have to exist an extent
+                * item with such offset, but this is out of the valid range.
+                */
+               return -EUCLEAN;
+       }
 
        ret = btrfs_previous_extent_item(extent_root, path, 0);
        if (ret) {
@@ -2870,6 +2877,10 @@ int btrfs_backref_iter_start(struct btrfs_backref_iter *iter, u64 bytenr)
        if (ret < 0)
                return ret;
        if (ret == 0) {
+               /*
+                * Key with offset -1 found, there would have to exist an extent
+                * item with such offset, but this is out of the valid range.
+                */
                ret = -EUCLEAN;
                goto release;
        }