Re: [syzbot] Re: kernel BUG in ocfs2_reserve_suballoc_bits()

From: syzbot
Date: Wed Nov 20 2024 - 03:15:16 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.

***

Subject: Re: kernel BUG in ocfs2_reserve_suballoc_bits()
Author: dmantipov@xxxxxxxxx

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git bf9aa14fc523d2763fc9a10672a709224e8fcaf4

diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 60df52e4c1f8..d65326d36b1c 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -2440,6 +2440,13 @@ int ocfs2_inode_lock_full_nested(struct inode *inode,

status = 0;
acquired = 0;
+
+ /* Do not trust a filesystem which is known for containing errors. */
+ if (ocfs2_has_errors(osb)) {
+ status = -EINVAL;
+ goto bail;
+ }
+
/* We'll allow faking a readonly metadata lock for
* rodevices. */
if (ocfs2_is_hard_readonly(osb)) {
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index 51c52768132d..a48f79ca750a 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -665,6 +665,17 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
return ret;
}

+static inline int ocfs2_has_errors(struct ocfs2_super *osb)
+{
+ int ret;
+
+ spin_lock(&osb->osb_lock);
+ ret = osb->osb_flags & OCFS2_OSB_ERROR_FS;
+ spin_unlock(&osb->osb_lock);
+
+ return ret;
+}
+
static inline int ocfs2_clusterinfo_valid(struct ocfs2_super *osb)
{
return (osb->s_feature_incompat &