From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 BAC7C18DB01 for ; Fri, 1 May 2026 11:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633371; cv=none; b=IuUYCxUAXqkIauLsAGP1mrOyatQjY/y+ayINbYVK9fFwTswMLp8/AE7y6OR1/lO5vtyPZXoPgWl0qj0YZQ4oqlWmuSoxjN05LBvGXHaqD7ab6o75L9Ztsj5vvMCnXprkeMpwifg5ZYDVc++HKliwfuNcXpIJt90VEg0IfgBq5yo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777633371; c=relaxed/simple; bh=6HjCTBRsWx1vc0YtSk64cmudc+766gGE5dQ+9vFy68I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uuJtzCfMpbWucMen8u4edKnnJ+4B1D/ULzpUu+nljXGJFji9xCB/ebKM3mRpBB9wmW3SKf/w8agfrjN1AKTRzyb/Jrir7WomC3V6fl7aUSi75Dz0Ool35g0l7YlBz/5mCmxBlieidPFtR9D1tpYYe98FjhwnqOjl9ePPHNZGPVE= 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=IotO8lox; arc=none smtp.client-ip=209.85.128.48 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="IotO8lox" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-488ba840146so14904475e9.1 for ; Fri, 01 May 2026 04:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777633368; x=1778238168; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=t+8L5WJt5aFDWaIjaWK7lYM1zW6O2ZzLXWTAE6+TQR0=; b=IotO8loxjsV18VYUuL5BmYZYtk/bnjvkD2FlvccTKRjw3EmLvxhUWBOk+pwk9DTX/F 5D8SvUoqtd5IjrbaPRPzCN/Ze7JuHx1iBBJxWE4Jdw4sZVRPzuKPBiB6BObrh3yFdQNh PzRENywIb8rDvqL9wOCITFiqWsecYs+P0YiK9guow2u1SEFmml3uVwOiOVp/lQ7WIS4j 4bhr8woElvKzkXONWnQnnEXgIdQ1YRjl+eOTwErWn/a2DfQ2He5iqXw9Bv2azzPZQRBr Rg3qxend6IZ/gMljqWiwb/RL/FtAZD1GmEfcyjj+RItimw/513L6drBSVdPX96fJFNym HfTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777633368; x=1778238168; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=t+8L5WJt5aFDWaIjaWK7lYM1zW6O2ZzLXWTAE6+TQR0=; b=E39GNd0pIFOwIww64xas03W0JrTU+OZKW3vvcVUa2/wyVP11A/DpYdObpQc2eUuA6W UfUSCAVK708mJiUho4tyXnRkbXPJ5r4I1rjBBPCryUQCrK+V4hR4nG7+pS89L8RmynkT kCTBzXVTcfXLjkybuZPGhx28xYO1D68OA8mIRv5HBsNFwhWub3Yznj9szJcnx+Dxxdoh WMfXOnpdzg0iVeIXYjtcyTl68TgUytIX5q77Vdotk+naHoz0s82TCFn1SueQU8+Yn6UX DObFv/7MYPXGDTczN4yqjUAMUHIT0U3hO+tEOm0wBKQOxQIvF6Kc1bPQ/i0MoEWYuw4g g+Cg== X-Forwarded-Encrypted: i=1; AFNElJ8Er6RZcrePqbz9brPix9W9DJliQie6wiR/PsiXbUdnq+8YW1jmHL9Dd/9mvxLmzkjm0ZIiZ6osxiInDHI=@vger.kernel.org X-Gm-Message-State: AOJu0YxJhINw8jDQJ5m1atACjq/pVHWaUzBoedgj/K6Is9KF/iW1mMFS RXqW0saZ74DBFwh8VqJ+rfaDwd5CaUnT7JDeR7EqABj5h7l58y/8u30= X-Gm-Gg: AeBDiet4MBFHCBvwdnHMXyad7lZgPMfz+w+Hy3vhMilGaVexdAWBnOqH8PsFUBFUueF rl/J/TFTQTdw9XzsIS6S9cMKod4mtFTKgTcHQGuq1R2vml0b3bqZGhS2K2uMpg1UqYVUZL9SV0V m7Bf3bU6HxEzLXblreqc2W/nySBcfQOqqFDXxGbBMK2f9FnzWG5rblDNSW95cziIEzj/23Hd4/h uSIy0dYhNbrKsehlQmyoIG+8GRn6ZQUHQtFxdjfomLKF5yCOczKU5MVTm6yqLU5G3YYvohm2v/G YRAE7HXZgNMnx/4FlVohZH0VPvZb4xAJVD5fRq+HDI9oC3eNQNNTu/fv5f5PnfEKwRNLQ1F0Z9F Xi9OaxQK31Pn+nlJ6cJC4Y0bZZSQ8Ap1qODeHqej+3IpafBVfsydr1yvBwZr1O/fQTllJIMpBpv vzfhoo4Tx7fuPYWw== X-Received: by 2002:a05:600c:8901:b0:48a:7a10:4f47 with SMTP id 5b1f17b1804b1-48a83d6e15fmr81071565e9.3.1777633367941; Fri, 01 May 2026 04:02:47 -0700 (PDT) Received: from debian.. ([2001:41d0:303:db6b::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a8eb3427fsm79491905e9.0.2026.05.01.04.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 04:02:47 -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+e84662c5f30b8c401437@syzkaller.appspotmail.com Subject: [PATCH 1/3] jffs2: always stop garbage collection thread on unmount Date: Fri, 1 May 2026 11:02:44 +0000 Message-ID: <20260501110246.50647-1-tristmd@gmail.com> X-Mailer: git-send-email 2.47.3 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_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@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=e84662c5f30b8c401437 Tested-by: syzbot+e84662c5f30b8c401437@syzkaller.appspotmail.com Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani --- 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