bcachefs: Validate that we read the correct btree node
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 12 May 2020 22:34:16 +0000 (18:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:39 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_io.c

index 32bd193a85c594c00d1e90a211a296716e1b1247..a5888de327fc44346fb5c8ef2ca9fc6cec5ac6aa 100644 (file)
@@ -736,6 +736,17 @@ static int validate_bset(struct bch_fs *c, struct btree *b,
                struct btree_node *bn =
                        container_of(i, struct btree_node, keys);
                /* These indicate that we read the wrong btree node: */
+
+               if (b->key.k.type == KEY_TYPE_btree_ptr_v2) {
+                       struct bch_btree_ptr_v2 *bp =
+                               &bkey_i_to_btree_ptr_v2(&b->key)->v;
+
+                       /* XXX endianness */
+                       btree_err_on(bp->seq != bn->keys.seq,
+                                    BTREE_ERR_MUST_RETRY, c, b, NULL,
+                                    "incorrect sequence number (wrong btree node)");
+               }
+
                btree_err_on(BTREE_NODE_ID(bn) != b->c.btree_id,
                             BTREE_ERR_MUST_RETRY, c, b, i,
                             "incorrect btree id");