[PATCH 1/3] jffs2: always stop garbage collection thread on unmount
Tristan Madani
tristmd at gmail.com
Fri May 1 04:02:44 PDT 2026
From: Tristan Madani <tristan at talencesecurity.com>
jffs2_kill_sb() skips stopping the GC thread when the filesystem
is mounted read-only. However, a filesystem can be remounted
read-only while the GC thread is still running. In that case,
jffs2_stop_garbage_collect_thread() is never called, and the GC
thread continues to run after kfree(c), accessing freed memory.
The GC thread accesses c->gc_task, c->gc_mtd, and the full
jffs2_sb_info structure during jffs2_garbage_collect_pass().
After kfree(c), any of these accesses is a use-after-free.
Remove the sb_rdonly() check so the GC thread is always stopped
before freeing the superblock info. jffs2_stop_garbage_collect_thread()
already handles the case where gc_task is NULL (no thread running),
so this is safe for the common case of a clean read-only mount.
Reported-by: syzbot+e84662c5f30b8c401437 at syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e84662c5f30b8c401437
Tested-by: syzbot+e84662c5f30b8c401437 at syzkaller.appspotmail.com
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable at vger.kernel.org
Signed-off-by: Tristan Madani <tristan at talencesecurity.com>
---
fs/jffs2/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 81396a092ba88..c846b435a38b6 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -345,7 +345,7 @@ static void jffs2_put_super (struct super_block *sb)
static void jffs2_kill_sb(struct super_block *sb)
{
struct jffs2_sb_info *c = JFFS2_SB_INFO(sb);
- if (c && !sb_rdonly(sb))
+ if (c)
jffs2_stop_garbage_collect_thread(c);
kill_mtd_super(sb);
kfree(c);
--
2.47.3
More information about the linux-mtd
mailing list