Skip to content

Commit 9e7cfb3

Browse files
author
Kent Overstreet
committed
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 <[email protected]>
1 parent e3fd3fa commit 9e7cfb3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

fs/bcachefs/recovery.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ static int journal_replay_entry_early(struct bch_fs *c,
326326
case BCH_JSET_ENTRY_btree_root: {
327327
struct btree_root *r;
328328

329+
if (fsck_err_on(entry->btree_id >= BTREE_ID_NR_MAX,
330+
c, invalid_btree_id,
331+
"invalid btree id %u (max %u)",
332+
entry->btree_id, BTREE_ID_NR_MAX))
333+
return 0;
334+
329335
while (entry->btree_id >= c->btree_roots_extra.nr + BTREE_ID_NR) {
330336
ret = darray_push(&c->btree_roots_extra, (struct btree_root) { NULL });
331337
if (ret)
@@ -415,7 +421,7 @@ static int journal_replay_entry_early(struct bch_fs *c,
415421
atomic64_set(&c->io_clock[clock->rw].now, le64_to_cpu(clock->time));
416422
}
417423
}
418-
424+
fsck_err:
419425
return ret;
420426
}
421427

fs/bcachefs/sb-errors_format.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@
273273
x(sb_clean_entry_overrun, 267) \
274274
x(btree_ptr_v2_written_0, 268) \
275275
x(subvol_snapshot_bad, 269) \
276-
x(subvol_inode_bad, 270)
276+
x(subvol_inode_bad, 270) \
277+
x(alloc_key_stripe_sectors_wrong, 271) \
278+
x(accounting_mismatch, 272) \
279+
x(accounting_replicas_not_marked, 273) \
280+
x(invalid_btree_id, 274)
277281

278282
enum bch_sb_error_id {
279283
#define x(t, n) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)