Skip to content

Commit 3fd27e9

Browse files
JungerBoyoKent Overstreet
authored andcommitted
bcachefs: init freespace inited bits to 0 in bch2_fs_initialize
Initialize freespace_initialized bits to 0 in member's flags and update member's cached version for each device in bch2_fs_initialize. It's possible for the bits to be set to 1 before fs is initialized and if call to bch2_trans_mark_dev_sbs (just before bch2_fs_freespace_init) fails bits remain to be 1 which can later indirectly trigger BUG condition in bch2_bucket_alloc_freelist during shutdown. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2b6a17991a6af64f9489 Fixes: bbe682c ("bcachefs: Ensure devices are always correctly initialized") Suggested-by: Kent Overstreet <[email protected]> Signed-off-by: Piotr Zalewski <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent c1fa854 commit 3fd27e9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/bcachefs/recovery.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ int bch2_fs_initialize(struct bch_fs *c)
10011001
struct bch_inode_unpacked root_inode, lostfound_inode;
10021002
struct bkey_inode_buf packed_inode;
10031003
struct qstr lostfound = QSTR("lost+found");
1004+
struct bch_member *m;
10041005
int ret;
10051006

10061007
bch_notice(c, "initializing new filesystem");
@@ -1017,6 +1018,14 @@ int bch2_fs_initialize(struct bch_fs *c)
10171018
SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, bcachefs_metadata_version_current);
10181019
bch2_write_super(c);
10191020
}
1021+
1022+
for_each_member_device(c, ca) {
1023+
m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
1024+
SET_BCH_MEMBER_FREESPACE_INITIALIZED(m, false);
1025+
ca->mi = bch2_mi_to_cpu(m);
1026+
}
1027+
1028+
bch2_write_super(c);
10201029
mutex_unlock(&c->sb_lock);
10211030

10221031
c->curr_recovery_pass = BCH_RECOVERY_PASS_NR;

0 commit comments

Comments
 (0)