lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241020170708.67044-2-pZ010001011111@proton.me>
Date: Sun, 20 Oct 2024 17:08:45 +0000
From: Piotr Zalewski <pZ010001011111@...ton.me>
To: kent.overstreet@...ux.dev, linux-bcachefs@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: skhan@...uxfoundation.org, Piotr Zalewski <pZ010001011111@...ton.me>, syzbot+2b6a17991a6af64f9489@...kaller.appspotmail.com
Subject: [PATCH v1] bcachefs: set freespace inited to false if trans_mark_dev_sbs fails

In bch2_fs_initialize if bch2_trans_mark_dev_sbs fails, set freespace
initialized bits to 0 in member's flags and update member cached version
for each device. bch2_trans_mark_dev_sbs fails just before freespace
init which can left freespace init bits set to true erroneously which later
can indirectly trigger BUG condition in bch2_bucket_alloc_freelist[1].

[1] https://syzkaller.appspot.com/bug?extid=2b6a17991a6af64f9489

Reported-by: syzbot+2b6a17991a6af64f9489@...kaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2b6a17991a6af64f9489
Fixes: bbe682c76789 ("bcachefs: Ensure devices are always correctly initialized")
Signed-off-by: Piotr Zalewski <pZ010001011111@...ton.me>
---
 fs/bcachefs/recovery.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 67bba156cce9..bcec79122f65 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -1031,6 +1031,7 @@ int bch2_fs_initialize(struct bch_fs *c)
 	struct bkey_inode_buf packed_inode;
 	struct qstr lostfound = QSTR("lost+found");
 	int ret;
+	struct bch_member *m;
 
 	bch_notice(c, "initializing new filesystem");
 	set_bit(BCH_FS_new_fs, &c->flags);
@@ -1086,8 +1087,17 @@ int bch2_fs_initialize(struct bch_fs *c)
 	bch_verbose(c, "marking superblocks");
 	ret = bch2_trans_mark_dev_sbs(c);
 	bch_err_msg(c, ret, "marking superblocks");
-	if (ret)
+	if (ret) {
+		mutex_lock(&c->sb_lock);
+		for_each_member_device(c, ca) {
+			m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
+			SET_BCH_MEMBER_FREESPACE_INITIALIZED(m, false);
+			ca->mi = bch2_mi_to_cpu(m);
+		}
+		mutex_unlock(&c->sb_lock);
+
 		goto err;
+	}
 
 	for_each_online_member(c, ca)
 		ca->new_fs_bucket_idx = 0;
-- 
2.47.0



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ