Skip to content

Commit a319aea

Browse files
author
Kent Overstreet
committed
bcachefs: Fix missing bounds checks in bch2_alloc_read()
We were checking that the alloc key was for a valid device, but not a valid bucket. This is the upgrade path from versions prior to bcachefs being mainlined. Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent 573ddcd commit a319aea

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,16 @@ int bch2_alloc_read(struct bch_fs *c)
639639
continue;
640640
}
641641

642+
if (k.k->p.offset < ca->mi.first_bucket) {
643+
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode, ca->mi.first_bucket));
644+
continue;
645+
}
646+
647+
if (k.k->p.offset >= ca->mi.nbuckets) {
648+
bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
649+
continue;
650+
}
651+
642652
struct bch_alloc_v4 a;
643653
*bucket_gen(ca, k.k->p.offset) = bch2_alloc_to_v4(k, &a)->gen;
644654
0;

0 commit comments

Comments
 (0)