]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: handle invalid extent item reference found in find_first_extent_item()
authorDavid Sterba <dsterba@suse.com>
Wed, 24 Jan 2024 21:49:02 +0000 (22:49 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Mar 2024 15:24:51 +0000 (16:24 +0100)
The find_first_extent_item() 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.

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

index 0123d272892373b3465c942e75e181d3bc77e681..c4bd0e60db59253f280236740d23ed1c5b7b92f7 100644 (file)
@@ -1390,8 +1390,15 @@ static int find_first_extent_item(struct btrfs_root *extent_root,
        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.
+                */
+               btrfs_release_path(path);
+               return -EUCLEAN;
+       }
 
-       ASSERT(ret > 0);
        /*
         * Here we intentionally pass 0 as @min_objectid, as there could be
         * an extent item starting before @search_start.