]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bcachefs: Check for invalid btree IDs
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 17 Jun 2024 13:26:54 +0000 (09:26 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 19 Jun 2024 22:27:23 +0000 (18:27 -0400)
We can only handle btree IDs up to 62, since the btree id (plus the type
for interior btree nodes) has to fit ito a 64 bit bitmask - check for
invalid ones to avoid invalid shifts later.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/recovery.c
fs/bcachefs/sb-errors_format.h

index cf513fc79ce4809b368adfd90cddbf6a510642c3..e632da69196ccf8988ba7efcd743559e713354c0 100644 (file)
@@ -326,6 +326,12 @@ static int journal_replay_entry_early(struct bch_fs *c,
        case BCH_JSET_ENTRY_btree_root: {
                struct btree_root *r;
 
+               if (fsck_err_on(entry->btree_id >= BTREE_ID_NR_MAX,
+                               c, invalid_btree_id,
+                               "invalid btree id %u (max %u)",
+                               entry->btree_id, BTREE_ID_NR_MAX))
+                       return 0;
+
                while (entry->btree_id >= c->btree_roots_extra.nr + BTREE_ID_NR) {
                        ret = darray_push(&c->btree_roots_extra, (struct btree_root) { NULL });
                        if (ret)
@@ -415,7 +421,7 @@ static int journal_replay_entry_early(struct bch_fs *c,
                atomic64_set(&c->io_clock[clock->rw].now, le64_to_cpu(clock->time));
        }
        }
-
+fsck_err:
        return ret;
 }
 
index 84d2763bd597bdcaa8c80b912032d75ac35107bf..1d1251f1bb205a154056913b070615cfe3bda31f 100644 (file)
        x(sb_clean_entry_overrun,                               267)    \
        x(btree_ptr_v2_written_0,                               268)    \
        x(subvol_snapshot_bad,                                  269)    \
-       x(subvol_inode_bad,                                     270)
+       x(subvol_inode_bad,                                     270)    \
+       x(alloc_key_stripe_sectors_wrong,                       271)    \
+       x(accounting_mismatch,                                  272)    \
+       x(accounting_replicas_not_marked,                       273)    \
+       x(invalid_btree_id,                                     274)
 
 enum bch_sb_error_id {
 #define x(t, n) BCH_FSCK_ERR_##t = n,