From: Chaohai Chen <wdhh6@aliyun.com>
To: syzbot+49c659b5564b2a44083c@syzkaller.appspotmail.com
Cc: dwmw2@infradead.org, linux-kernel@vger.kernel.org,
linux-mtd@lists.infradead.org, richard@nod.at,
syzkaller-bugs@googlegroups.com, wdhh6@aliyun.com
Subject: [PATCH] jffs2: don't start the GC thread on a read-only superblock
Date: Wed, 28 Oct 2026 16:09:55 +0800 [thread overview]
Message-ID: <20261028080955.290774-1-wdhh6@aliyun.com> (raw)
In-Reply-To: <6adfffa9.6200f071.51519.0f0e.GAE@google.com>
jffs2_do_remount_fs() derives the read-write state from fc->sb_flags,
but fc->sb_flags is only meaningful for the bits selected by
fc->sb_flags_mask.
fspick() builds its fs_context with sb_flags=0 and sb_flags_mask=0,
which means "leave every superblock flag alone"; JFFS2 misreads that
as "the filesystem is becoming read-write" and starts jffs2_gcd_mtdX
although the superblock stays read-only, and reconfigure_super()
then leaves sb->s_flags untouched.
The thread then outlives its superblock: jffs2_kill_sb() stops the
garbage collect thread only when !sb_rdonly(sb), so kfree(c) runs
while the thread is still alive and the next GC pass dereferences
freed memory.
Compute the resulting read-only state from fc->sb_flags only when
SB_RDONLY is part of fc->sb_flags_mask, falling back to the current
state otherwise, and stop any running thread unconditionally before
deciding whether to restart it.
Fixes: ec10a24f10c8 ("vfs: Convert jffs2 to use the new mount API")
Reported-by: syzbot+49c659b5564b2a44083c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=49c659b5564b2a44083c
Signed-off-by: Chaohai Chen <wdhh6@aliyun.com>
---
fs/jffs2/fs.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 05cf860307c7..6d04dfa7b910 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -396,6 +396,15 @@ void jffs2_dirty_inode(struct inode *inode, int flags)
int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc)
{
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
+ /*
+ * fc->sb_flags is only meaningful for the bits selected by
+ * fc->sb_flags_mask. fspick() passes a mask of 0, which leaves the
+ * read-only state untouched - that must not be read as "becoming
+ * read-write", or we would spawn a GC thread on a superblock that
+ * stays read-only (and which jffs2_kill_sb() would then not stop).
+ */
+ bool will_be_ro = (fc->sb_flags_mask & SB_RDONLY) ?
+ !!(fc->sb_flags & SB_RDONLY) : sb_rdonly(sb);
if (c->flags & JFFS2_SB_FLAG_RO && !sb_rdonly(sb))
return -EROFS;
@@ -404,14 +413,14 @@ int jffs2_do_remount_fs(struct super_block *sb, struct fs_context *fc)
This also catches the case where it was stopped and this
is just a remount to restart it.
Flush the writebuffer, if necessary, else we loose it */
+ jffs2_stop_garbage_collect_thread(c);
if (!sb_rdonly(sb)) {
- jffs2_stop_garbage_collect_thread(c);
mutex_lock(&c->alloc_sem);
jffs2_flush_wbuf_pad(c);
mutex_unlock(&c->alloc_sem);
}
- if (!(fc->sb_flags & SB_RDONLY))
+ if (!will_be_ro)
jffs2_start_garbage_collect_thread(c);
fc->sb_flags |= SB_NOATIME;
--
2.43.7
next prev parent reply other threads:[~2026-10-28 8:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 1:34 [syzbot] [jffs2?] KASAN: slab-use-after-free Read in jffs2_erase_pending_blocks (2) syzbot
2026-10-28 8:09 ` Chaohai Chen [this message]
2026-10-29 3:37 ` [PATCH] jffs2: don't start the GC thread on a read-only superblock Zhan Xusheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261028080955.290774-1-wdhh6@aliyun.com \
--to=wdhh6@aliyun.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=syzbot+49c659b5564b2a44083c@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®