bcachefs: Add missing key type checks to check_snapshot_exists()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 19 Jun 2025 18:32:57 +0000 (14:32 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 19 Jun 2025 18:37:04 +0000 (14:37 -0400)
For now we only have one key type in these btrees, but forward
compatibility means we do have to check.

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

index 38aeaa128d2733c99ecdf8f2cd5c6cbf1bafcf37..4c43d2a2c1f5bb1752b6b0ff7c950865b7b49785 100644 (file)
@@ -871,7 +871,8 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
 
        for_each_btree_key_norestart(trans, iter, BTREE_ID_snapshot_trees, POS_MIN,
                                     0, k, ret) {
-               if (le32_to_cpu(bkey_s_c_to_snapshot_tree(k).v->root_snapshot) == id) {
+               if (k.k->type == KEY_TYPE_snapshot_tree &&
+                   le32_to_cpu(bkey_s_c_to_snapshot_tree(k).v->root_snapshot) == id) {
                        tree_id = k.k->p.offset;
                        break;
                }
@@ -899,7 +900,8 @@ static int check_snapshot_exists(struct btree_trans *trans, u32 id)
 
        for_each_btree_key_norestart(trans, iter, BTREE_ID_subvolumes, POS_MIN,
                                     0, k, ret) {
-               if (le32_to_cpu(bkey_s_c_to_subvolume(k).v->snapshot) == id) {
+               if (k.k->type == KEY_TYPE_subvolume &&
+                   le32_to_cpu(bkey_s_c_to_subvolume(k).v->snapshot) == id) {
                        snapshot->v.subvol = cpu_to_le32(k.k->p.offset);
                        SET_BCH_SNAPSHOT_SUBVOL(&snapshot->v, true);
                        break;