]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: fsck: Fix oops in key_visible_in_snapshot()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 17 Jun 2025 20:49:40 +0000 (16:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 18 Jun 2025 00:45:26 +0000 (20:45 -0400)
The normal fsck code doesn't call key_visible_in_snapshot() with an
empty list of snapshot IDs seen (the current snapshot ID will always be
on the list), but str_hash_repair_key() ->
bch2_get_snapshot_overwrites() can, and that's totally fine as long as
we check for it.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fsck.c

index 57ddc20a5cce16c461fd01778e207cb7b8621703..9920f1affc5ba2b38166544138fa3e6508d77f80 100644 (file)
@@ -728,14 +728,8 @@ static int snapshots_seen_update(struct bch_fs *c, struct snapshots_seen *s,
 static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *seen,
                                    u32 id, u32 ancestor)
 {
-       ssize_t i;
-
        EBUG_ON(id > ancestor);
 
-       /* @ancestor should be the snapshot most recently added to @seen */
-       EBUG_ON(ancestor != seen->pos.snapshot);
-       EBUG_ON(ancestor != darray_last(seen->ids));
-
        if (id == ancestor)
                return true;
 
@@ -751,11 +745,8 @@ static bool key_visible_in_snapshot(struct bch_fs *c, struct snapshots_seen *see
         * numerically, since snapshot ID lists are kept sorted, so if we find
         * an id that's an ancestor of @id we're done:
         */
-
-       for (i = seen->ids.nr - 2;
-            i >= 0 && seen->ids.data[i] >= id;
-            --i)
-               if (bch2_snapshot_is_ancestor(c, id, seen->ids.data[i]))
+       darray_for_each_reverse(seen->ids, i)
+               if (*i != ancestor && bch2_snapshot_is_ancestor(c, id, *i))
                        return false;
 
        return true;