Skip to content

Commit f8f1dde

Browse files
author
Kent Overstreet
committed
bcachefs: Fix missing validation for bch_backpointer.level
This fixes an assertion pop where we try to navigate to the target of the backpointer, and the path level isn't what we expect. Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent 27a036a commit f8f1dde

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

fs/bcachefs/backpointers.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ int bch2_backpointer_validate(struct bch_fs *c, struct bkey_s_c k,
5252
enum bch_validate_flags flags)
5353
{
5454
struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);
55+
int ret = 0;
56+
57+
bkey_fsck_err_on(bp.v->level > BTREE_MAX_DEPTH,
58+
c, backpointer_level_bad,
59+
"backpointer level bad: %u >= %u",
60+
bp.v->level, BTREE_MAX_DEPTH);
5561

5662
rcu_read_lock();
5763
struct bch_dev *ca = bch2_dev_rcu_noerror(c, bp.k->p.inode);
@@ -64,7 +70,6 @@ int bch2_backpointer_validate(struct bch_fs *c, struct bkey_s_c k,
6470
struct bpos bucket = bp_pos_to_bucket(ca, bp.k->p);
6571
struct bpos bp_pos = bucket_pos_to_bp_noerror(ca, bucket, bp.v->bucket_offset);
6672
rcu_read_unlock();
67-
int ret = 0;
6873

6974
bkey_fsck_err_on((bp.v->bucket_offset >> MAX_EXTENT_COMPRESS_RATIO_SHIFT) >= ca->mi.bucket_size ||
7075
!bpos_eq(bp.k->p, bp_pos),

fs/bcachefs/sb-errors_format.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ enum bch_fsck_flags {
136136
x(bucket_gens_nonzero_for_invalid_buckets, 122, FSCK_AUTOFIX) \
137137
x(need_discard_freespace_key_to_invalid_dev_bucket, 123, 0) \
138138
x(need_discard_freespace_key_bad, 124, 0) \
139+
x(discarding_bucket_not_in_need_discard_btree, 291, 0) \
139140
x(backpointer_bucket_offset_wrong, 125, 0) \
141+
x(backpointer_level_bad, 294, 0) \
140142
x(backpointer_to_missing_device, 126, 0) \
141143
x(backpointer_to_missing_alloc, 127, 0) \
142144
x(backpointer_to_missing_ptr, 128, 0) \
@@ -177,7 +179,9 @@ enum bch_fsck_flags {
177179
x(ptr_stripe_redundant, 163, 0) \
178180
x(reservation_key_nr_replicas_invalid, 164, 0) \
179181
x(reflink_v_refcount_wrong, 165, 0) \
182+
x(reflink_v_pos_bad, 292, 0) \
180183
x(reflink_p_to_missing_reflink_v, 166, 0) \
184+
x(reflink_refcount_underflow, 293, 0) \
181185
x(stripe_pos_bad, 167, 0) \
182186
x(stripe_val_size_bad, 168, 0) \
183187
x(stripe_csum_granularity_bad, 290, 0) \
@@ -302,7 +306,7 @@ enum bch_fsck_flags {
302306
x(accounting_key_replicas_devs_unsorted, 280, FSCK_AUTOFIX) \
303307
x(accounting_key_version_0, 282, FSCK_AUTOFIX) \
304308
x(logged_op_but_clean, 283, FSCK_AUTOFIX) \
305-
x(MAX, 291, 0)
309+
x(MAX, 295, 0)
306310

307311
enum bch_sb_error_id {
308312
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)