Skip to content

Commit 6b8cbfc

Browse files
author
Kent Overstreet
committed
bcachefs: Fix assert in bch2_alloc_v4_invalid()
Reported-by: syzbot+10827fa6b176e1acf1d0@syzkaller.appspotmail.com Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 9a0ec04 commit 6b8cbfc

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

fs/bcachefs/alloc_background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ int bch2_alloc_v4_invalid(struct bch_fs *c, struct bkey_s_c k,
244244
struct bkey_s_c_alloc_v4 a = bkey_s_c_to_alloc_v4(k);
245245
int ret = 0;
246246

247-
bkey_fsck_err_on(alloc_v4_u64s(a.v) > bkey_val_u64s(k.k), c, err,
247+
bkey_fsck_err_on(alloc_v4_u64s_noerror(a.v) > bkey_val_u64s(k.k), c, err,
248248
alloc_v4_val_size_bad,
249249
"bad val size (%u > %zu)",
250-
alloc_v4_u64s(a.v), bkey_val_u64s(k.k));
250+
alloc_v4_u64s_noerror(a.v), bkey_val_u64s(k.k));
251251

252252
bkey_fsck_err_on(!BCH_ALLOC_V4_BACKPOINTERS_START(a.v) &&
253253
BCH_ALLOC_V4_NR_BACKPOINTERS(a.v), c, err,

fs/bcachefs/alloc_background.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,17 @@ static inline struct bpos alloc_freespace_pos(struct bpos pos, struct bch_alloc_
126126
return pos;
127127
}
128128

129-
static inline unsigned alloc_v4_u64s(const struct bch_alloc_v4 *a)
129+
static inline unsigned alloc_v4_u64s_noerror(const struct bch_alloc_v4 *a)
130130
{
131-
unsigned ret = (BCH_ALLOC_V4_BACKPOINTERS_START(a) ?:
131+
return (BCH_ALLOC_V4_BACKPOINTERS_START(a) ?:
132132
BCH_ALLOC_V4_U64s_V0) +
133133
BCH_ALLOC_V4_NR_BACKPOINTERS(a) *
134134
(sizeof(struct bch_backpointer) / sizeof(u64));
135+
}
135136

137+
static inline unsigned alloc_v4_u64s(const struct bch_alloc_v4 *a)
138+
{
139+
unsigned ret = alloc_v4_u64s_noerror(a);
136140
BUG_ON(ret > U8_MAX - BKEY_U64s);
137141
return ret;
138142
}

0 commit comments

Comments
 (0)