From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BD2539B482 for ; Fri, 1 May 2026 11:02:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633372; cv=none; b=U1zIY0Mp/kOmAxjcnFWWxR+J6JqRH80nRA1S2/59oAKylkuJQLKm/BMcXYwcFAJnIW+Kxgk6zvyjjSVpeuX/ahW71Cli3uDmJ/Tmxey/4H19U16sNjQGnKemMfhmbe7WaxEzgYFlIsDN2idj+oql3XauI8i1zX3qFqc0D3JSL0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633372; c=relaxed/simple; bh=FO4uYCslB8uw9GgCcf+U9hU9S4PuFGJx/NZIUxdIVlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kv1qQXY7XhSpjr3tSLBtCiVBB35/eaCNYaf6OvxyYX2uer9abMJs19wAucw/wCGA7gPngd7jYp/zg2XfVqL8UQ18kN+59xpGtWK9/z024ieWi2oGvFB4kwGAkLxkMUqj9nkBJQGCYocHXEVIQ2o9rPGxX7x4xIf+SSTqML5UVvM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AcQz8oOA; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AcQz8oOA" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-488b8bc6bc9so11560195e9.3 for ; Fri, 01 May 2026 04:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777633370; x=1778238170; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q+0lxbCgi4fdg+cPkHoOKKRDCXmHxPZDe6bIN/WeBEA=; b=AcQz8oOAmxnQUDjm5uUaNVvuuYCpcAtxBNHyQ5Xj1iNUV9bZDTELXiIrcy42birTc1 27oVCyfA8lB2jNO2d0x62MKc8by6ZEO+vUQRgHIMxrsZyP5nszSGkkOtkdyQkEsQxluY 9osBj66sxJqkt+lNkV6+4K/w5ADr1P2hH72fOxJfdsdq1qLJtXKdTPXtbdLZQ1CfbwPk izek5UGxuUir6t7Kgb3NAnMLEDyIa4k0iB0mh2m2wYSG3Ln0ZzFk7gjENs+5QcQpRnVe tdpFUMpUZxvhN5IOXsa4eFQqFkEnyrLf+CvEK0IwiAfbBuU5J9/fIsLVge0BahnwwtCa sX1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777633370; x=1778238170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=q+0lxbCgi4fdg+cPkHoOKKRDCXmHxPZDe6bIN/WeBEA=; b=bYK5z2OU14v5z2CTXLV/Z547GGeh8Sk+IkhqHP9obMr/JPx8M49vDO07a9uhuEivZR kGi9AoJAC2flHcPENnqe1TkJhaNIMF1POOcXpMp16FjmLHAMznvux/JOBBZSCOnsT1Ar DZIWa4XSBsExpEMeJALSJYcs2WYg0Wr3cOyjm8vvYTVe/U6DquoHq1BQwz2N9r2md4v5 Vyu8Cu1TcoKTdPFEFVByKLld3uMLEUFtcAhTYA3NiBndOC/YfXHP7rDBBrwSS1/Ukdvc ttQrrr3eJ+uIH3pYwsc8xezCXLXWC5vsbmc5pKcaS0o6mENYnjbzmUz/6D2ISSYM1Ejy GoHA== X-Forwarded-Encrypted: i=1; AFNElJ9SU2NZmmwN1n8e9ctZtyIWCeUsUr10fB/nR+JvbsE0aqf6c7UTFjbqmFh4mYZwIfNUfd3cNIHxS3ndc/4=@vger.kernel.org X-Gm-Message-State: AOJu0YwMk5lUztR5+IvAar0cgTD4DmDfymJcBdeG//tLwr6THG47tr2j AWFJojNJ6AXUNLMz2fJa5o2x4wlb/hdELt2YEj87f/9E6oxH9gjUnOo= X-Gm-Gg: AeBDietvnyQ6jP8V6zEiqZ46zummQL1k2rQGfjvo6mrMq5js3mBvwR8hCrzk6imQ3rl N9B3mnDcvx+ruTpWQuDvnqUGn7sBKy4y+cpexN4RWBjG7T76pqxPQLK1FMAngXu85oRPtFXtDxx XNeYOMjIb4Rr0/7ZL0w6RtQF+Je82Y7hYdynp9qdATwqopQGaB22sO8JxOFuHs8tcabh3pC4XSV ofAi7IEetCzhEhL9lehScoCSbDhzBxEMpmIVkQ3GqijkCaQqYgsokPkCyi6DYnEjSPomHMxSOIk nLDWZBrn4pLs/KjBCSxzDHAHg7Ve2Qpy/61h7gunLv3KcaW4KS71JmIeBET3kjJDR9BWgf3qnUo SwopvFYeOdb9lrGMI8CcMKmGKE8lqxFCa+0zUfdIWqsMB0VdzctR2rsOofufuRSEWACA53mhx+i z+Un9WDZ/yKa5kFQ== X-Received: by 2002:a05:600c:8710:b0:48a:581c:ead with SMTP id 5b1f17b1804b1-48a844448f9mr115645805e9.10.1777633369516; Fri, 01 May 2026 04:02:49 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8eb3427fsm79491905e9.0.2026.05.01.04.02.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:02:49 -0700 (PDT) From: Tristan Madani To: David Woodhouse , Richard Weinberger Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Tristan Madani , syzbot+61a9d95630970eece39d@syzkaller.appspotmail.com Subject: [PATCH 3/3] jffs2: fix GC thread BUG_ON during reconfigure via fspick Date: Fri, 1 May 2026 11:02:46 +0000 Message-ID: <20260501110246.50647-3-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260501110246.50647-1-tristmd@gmail.com> References: <20260501110246.50647-1-tristmd@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tristan Madani jffs2_do_remount_fs() uses fc->sb_flags to decide whether to start the garbage collection thread. However, when called via fspick(2) followed by fsconfig(FSCONFIG_CMD_RECONFIGURE), fc->sb_flags does not reflect the current mount state -- it only contains flags being explicitly changed (as indicated by fc->sb_flags_mask). When fspick() is called with flags=0 on a read-only mount, fc->sb_flags has SB_RDONLY clear (since SB_RDONLY is not in sb_flags_mask). This causes jffs2_start_garbage_collect_thread() to be called even though the filesystem remains read-only. On the second reconfigure, BUG_ON(c->gc_task) fires because the thread from the first call is still running. Fix this by computing the effective read-only state using both fc->sb_flags and fc->sb_flags_mask. Also unconditionally call jffs2_stop_garbage_collect_thread() before potentially restarting it, which is safe when gc_task is NULL and prevents the BUG_ON. Reported-by: syzbot+61a9d95630970eece39d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=61a9d95630970eece39d Tested-by: syzbot+61a9d95630970eece39d@syzkaller.appspotmail.com Fixes: ec10a24f10c8f ("vfs: Convert jffs2 to use the new mount API") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- fs/jffs2/fs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c index 6ada8369a7622..33574312b7abe 100644 --- a/fs/jffs2/fs.c +++ b/fs/jffs2/fs.c @@ -396,28 +396,28 @@ 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); + bool new_ro; if (c->flags & JFFS2_SB_FLAG_RO && !sb_rdonly(sb)) return -EROFS; - /* We stop if it was running, then restart if it needs to. - 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 */ + new_ro = (fc->sb_flags_mask & SB_RDONLY) ? + (fc->sb_flags & SB_RDONLY) : sb_rdonly(sb); + + 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 (!new_ro) jffs2_start_garbage_collect_thread(c); fc->sb_flags |= SB_NOATIME; return 0; } - /* jffs2_new_inode: allocate a new inode and inocache, add it to the hash, fill in the raw_inode while you're at it. */ struct inode *jffs2_new_inode (struct inode *dir_i, umode_t mode, struct jffs2_raw_inode *ri) -- 2.47.3