Skip to content

Commit 50a8a73

Browse files
bertschingertKent Overstreet
authored andcommitted
bcachefs: fix invalid memory access in bch2_fs_alloc() error path
When bch2_fs_alloc() gets an error before calling bch2_fs_btree_iter_init(), bch2_fs_btree_iter_exit() makes an invalid memory access because btree_trans_list is uninitialized. Signed-off-by: Thomas Bertschinger <[email protected]> Fixes: 6bd68ec ("bcachefs: Heap allocate btree_trans") Signed-off-by: Kent Overstreet <[email protected]>
1 parent 8bf7719 commit 50a8a73

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,10 +3214,9 @@ void bch2_fs_btree_iter_exit(struct bch_fs *c)
32143214
mempool_exit(&c->btree_trans_pool);
32153215
}
32163216

3217-
int bch2_fs_btree_iter_init(struct bch_fs *c)
3217+
void bch2_fs_btree_iter_init_early(struct bch_fs *c)
32183218
{
32193219
struct btree_transaction_stats *s;
3220-
int ret;
32213220

32223221
for (s = c->btree_transaction_stats;
32233222
s < c->btree_transaction_stats + ARRAY_SIZE(c->btree_transaction_stats);
@@ -3228,6 +3227,11 @@ int bch2_fs_btree_iter_init(struct bch_fs *c)
32283227

32293228
INIT_LIST_HEAD(&c->btree_trans_list);
32303229
seqmutex_init(&c->btree_trans_lock);
3230+
}
3231+
3232+
int bch2_fs_btree_iter_init(struct bch_fs *c)
3233+
{
3234+
int ret;
32313235

32323236
c->btree_trans_bufs = alloc_percpu(struct btree_trans_buf);
32333237
if (!c->btree_trans_bufs)

fs/bcachefs/btree_iter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ unsigned bch2_trans_get_fn_idx(const char *);
938938
void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);
939939

940940
void bch2_fs_btree_iter_exit(struct bch_fs *);
941+
void bch2_fs_btree_iter_init_early(struct bch_fs *);
941942
int bch2_fs_btree_iter_init(struct bch_fs *);
942943

943944
#endif /* _BCACHEFS_BTREE_ITER_H */

fs/bcachefs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
714714

715715
bch2_fs_copygc_init(c);
716716
bch2_fs_btree_key_cache_init_early(&c->btree_key_cache);
717+
bch2_fs_btree_iter_init_early(c);
717718
bch2_fs_btree_interior_update_init_early(c);
718719
bch2_fs_allocator_background_init(c);
719720
bch2_fs_allocator_foreground_init(c);

0 commit comments

Comments
 (0)