bcachefs: Guard against unknown k.k->type in __bkey_invalid()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 6 May 2024 02:33:05 +0000 (22:33 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 6 May 2024 14:58:17 +0000 (10:58 -0400)
For forwards compatibility we have to allow unknown key types, and only
run the checks that make sense against them.

Fix a missing guard on k.k->type being known.

Reported-by: syzbot+ae4dc916da3ce51f284f@syzkaller.appspotmail.com
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/bkey_methods.c

index db336a43fc083a79615e81ce9da37ff4877005f9..a275a9e8e341aa0669073625d6b39d376139739a 100644 (file)
@@ -171,8 +171,8 @@ int __bch2_bkey_invalid(struct bch_fs *c, struct bkey_s_c k,
        if (type >= BKEY_TYPE_NR)
                return 0;
 
-       bkey_fsck_err_on((type == BKEY_TYPE_btree ||
-                         (flags & BKEY_INVALID_COMMIT)) &&
+       bkey_fsck_err_on(k.k->type < KEY_TYPE_MAX &&
+                        (type == BKEY_TYPE_btree || (flags & BKEY_INVALID_COMMIT)) &&
                         !(bch2_key_types_allowed[type] & BIT_ULL(k.k->type)), c, err,
                         bkey_invalid_type_for_btree,
                         "invalid key type for btree %s (%s)",