bcachefs: Fix shift overflow in btree_lost_data()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 19 May 2024 21:08:15 +0000 (17:08 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 20 May 2024 09:37:26 +0000 (05:37 -0400)
Reported-by: syzbot+29f65db1a5fe427b5c56@syzkaller.appspotmail.com
Fixes: 55936afe1107 ("bcachefs: Flag btrees with missing data")
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bcachefs_format.h
fs/bcachefs/recovery.c

index 1bebba881d8997135cf4b7eee77721e97049a97b..d801e19cb4890e014589f44de53e1c1aa6355aaa 100644 (file)
@@ -1555,6 +1555,12 @@ enum btree_id {
        BTREE_ID_NR
 };
 
+/*
+ * Maximum number of btrees that we will _ever_ have under the current scheme,
+ * where we refer to them with bitfields
+ */
+#define BTREE_ID_NR_MAX                64
+
 static inline bool btree_id_is_alloc(enum btree_id id)
 {
        switch (id) {
index 1266916ac03f05600d3b3f049f3ee94458a96281..63f990f5c63a17e397401d9a1320d7bdf99db704 100644 (file)
@@ -35,6 +35,9 @@
 
 void bch2_btree_lost_data(struct bch_fs *c, enum btree_id btree)
 {
+       if (btree >= BTREE_ID_NR_MAX)
+               return;
+
        u64 b = BIT_ULL(btree);
 
        if (!(c->sb.btrees_lost_data & b)) {