Commit 50a8a732 authored by Thomas Bertschinger's avatar Thomas Bertschinger Committed by Kent Overstreet
Browse files

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: default avatarThomas Bertschinger <tahbertschinger@gmail.com>
Fixes: 6bd68ec2 ("bcachefs: Heap allocate btree_trans")
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 8bf77197
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -3214,10 +3214,9 @@ void bch2_fs_btree_iter_exit(struct bch_fs *c)
	mempool_exit(&c->btree_trans_pool);
}

int bch2_fs_btree_iter_init(struct bch_fs *c)
void bch2_fs_btree_iter_init_early(struct bch_fs *c)
{
	struct btree_transaction_stats *s;
	int ret;

	for (s = c->btree_transaction_stats;
	     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)

	INIT_LIST_HEAD(&c->btree_trans_list);
	seqmutex_init(&c->btree_trans_lock);
}

int bch2_fs_btree_iter_init(struct bch_fs *c)
{
	int ret;

	c->btree_trans_bufs = alloc_percpu(struct btree_trans_buf);
	if (!c->btree_trans_bufs)
+1 −0
Original line number Diff line number Diff line
@@ -938,6 +938,7 @@ unsigned bch2_trans_get_fn_idx(const char *);
void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);

void bch2_fs_btree_iter_exit(struct bch_fs *);
void bch2_fs_btree_iter_init_early(struct bch_fs *);
int bch2_fs_btree_iter_init(struct bch_fs *);

#endif /* _BCACHEFS_BTREE_ITER_H */
+1 −0
Original line number Diff line number Diff line
@@ -714,6 +714,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)

	bch2_fs_copygc_init(c);
	bch2_fs_btree_key_cache_init_early(&c->btree_key_cache);
	bch2_fs_btree_iter_init_early(c);
	bch2_fs_btree_interior_update_init_early(c);
	bch2_fs_allocator_background_init(c);
	bch2_fs_allocator_foreground_init(c);