Skip to content

Commit 9f25dbe

Browse files
author
Kent Overstreet
committed
bcachefs: Add missing validation for bch_stripe.csum_granularity_bits
Reported-by: [email protected] Signed-off-by: Kent Overstreet <[email protected]>
1 parent a319aea commit 9f25dbe

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

fs/bcachefs/ec.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ int bch2_stripe_validate(struct bch_fs *c, struct bkey_s_c k,
124124
"incorrect value size (%zu < %u)",
125125
bkey_val_u64s(k.k), stripe_val_u64s(s));
126126

127+
bkey_fsck_err_on(s->csum_granularity_bits >= 64,
128+
c, stripe_csum_granularity_bad,
129+
"invalid csum granularity (%u >= 64)",
130+
s->csum_granularity_bits);
131+
127132
ret = bch2_bkey_ptrs_validate(c, k, flags);
128133
fsck_err:
129134
return ret;
@@ -145,7 +150,11 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c,
145150
nr_data,
146151
s.nr_redundant);
147152
bch2_prt_csum_type(out, s.csum_type);
148-
prt_printf(out, " gran %u", 1U << s.csum_granularity_bits);
153+
prt_str(out, " gran ");
154+
if (s.csum_granularity_bits < 64)
155+
prt_printf(out, "%llu", 1ULL << s.csum_granularity_bits);
156+
else
157+
prt_printf(out, "(invalid shift %u)", s.csum_granularity_bits);
149158

150159
if (s.disk_label) {
151160
prt_str(out, " label");

fs/bcachefs/sb-errors_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ enum bch_fsck_flags {
180180
x(reflink_p_to_missing_reflink_v, 166, 0) \
181181
x(stripe_pos_bad, 167, 0) \
182182
x(stripe_val_size_bad, 168, 0) \
183+
x(stripe_csum_granularity_bad, 290, 0) \
183184
x(stripe_sector_count_wrong, 169, 0) \
184185
x(snapshot_tree_pos_bad, 170, 0) \
185186
x(snapshot_tree_to_missing_snapshot, 171, 0) \
@@ -301,7 +302,7 @@ enum bch_fsck_flags {
301302
x(accounting_key_replicas_devs_unsorted, 280, FSCK_AUTOFIX) \
302303
x(accounting_key_version_0, 282, FSCK_AUTOFIX) \
303304
x(logged_op_but_clean, 283, FSCK_AUTOFIX) \
304-
x(MAX, 290, 0)
305+
x(MAX, 291, 0)
305306

306307
enum bch_sb_error_id {
307308
#define x(t, n, ...) BCH_FSCK_ERR_##t = n,

0 commit comments

Comments
 (0)