summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2024-06-17 09:26:54 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2024-06-19 18:27:23 -0400
commit9e7cfb35e2668e542c333ed3ec4b0a951dd332ee (patch)
treed7c5f02d40f9822fa84d3d4645a6907db4aa60af /fs
parente3fd3faa453ce4cf4b6a0f3e29ee77d5d1b243a8 (diff)
bcachefs: Check for invalid btree IDs
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/recovery.c8
-rw-r--r--fs/bcachefs/sb-errors_format.h6
2 files changed, 12 insertions, 2 deletions
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index cf513fc79ce4..e632da69196c 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -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;
}
diff --git a/fs/bcachefs/sb-errors_format.h b/fs/bcachefs/sb-errors_format.h
index 84d2763bd597..1d1251f1bb20 100644
--- a/fs/bcachefs/sb-errors_format.h
+++ b/fs/bcachefs/sb-errors_format.h
@@ -273,7 +273,11 @@
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,