Commit f36dff28 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Validate that we read the correct btree node

Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a9310ab0
......@@ -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");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment