From nobody Sat Jul 25 02:11:17 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 0671642BC24 for ; Mon, 20 Jul 2026 14:17:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557042; cv=none; b=p8s/L8KPhof0KlWIkxGGlSog2Q6tYOqaAKN6RBTcozUKzwoaurfRIqSBb4G1kDdlx7zjL+SkY0j7fn/LVypItG/MsJ7csuCMrZvdCxoKVgXMljzoiA6cDuz4Dl4FXmQ27eGKqjJbI1UfYVy9vRiU5BoHAJJjiEG1Vb2nEhJhRrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784557042; c=relaxed/simple; bh=1LTkvmZGmZwJt/B8VQrglyJCuBupUAzm+QAjG/yRD1Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=STjMq72EousM30COUZow1jAFQyIhecYEarlxBGf1kUz+f0U8yczk1M2t5VyKtITNFo3qcFJj+ErO403V95SEAxbmtObU6QxWFahqNYbMOol44jeDaTnTwD5fjI194QJEJhVy+61qlTB9aFC/pYSRVuGArWXoP42WAVubrhWjiYg= 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=NZadcrQ/; arc=none smtp.client-ip=209.85.216.46 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="NZadcrQ/" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-38dc4553f62so8507912a91.0 for ; Mon, 20 Jul 2026 07:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784557040; x=1785161840; 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:content-type; bh=uwzswtIIaxm5d4gI976jZ15OSTycJLbOOHw5koXtiWE=; b=NZadcrQ/glP0ngITv3A2LgwhVrYtcYJEwvQoakObpgj535gDrJw8clH54rCHWmx1D1 apjRgdAIban6I+g+lghhDiZJVQQkcgJEq+fwys2sD7HneUp1G45WaSmVaK6UK/yDcUmD THPtsjXZgB/s2OtBpyGJkEOftNC14P+DiCyvgTnFTHio8H09M/DbZrGi8OiPrkfVlToM X2KkCY3ckE52YAoUCLwZIxFdISykZN+HhSpe+2dCe64cLWNRHVMfbzffzlurIn4dS+Pk 3OTlzVAqPehi9ZHhGr1NMYdcMkuXCWoid+vc3QX5Aj+1owN7bRXVCUIzwGz5c21lSMG0 WiZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784557040; x=1785161840; 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:content-type; bh=uwzswtIIaxm5d4gI976jZ15OSTycJLbOOHw5koXtiWE=; b=Nf6HvwKmMSMoDI7wkLdOthOOfetsSEMk2XFxBWv2ciAZp01AToNhPi0nBxPU0Bi7o6 zzbcbJ09ABRW46O2z28qj1bgoaLMu4XmgB0mUWQsZHNfP0fzQwI3IiWKqPe5WgI50LZ/ 57uuV7iDWvcOdsTfpVMVdZRdZZ3bG3t8IFWHFc+zTfYPbEYt4X+LqDeu2a54W4snrNX+ O1uANXv2QWuTvO2Waya3YFqlOUWZYTzoSJOgBi1f0/VdO9XguuVCmYZWALxUxecIWvWT ApvsceTlMSdCYZs9PN3UFBhsELyBazMJsBi6V1PzKopWknT9FEoqJtouUFQEM4NGSAjy 1TfQ== X-Forwarded-Encrypted: i=1; AHgh+RrPASxqdvWA6SWLgUpADg1+vRRd1OXhLMBvXmNOpl3V9Wz+rkCg3LNx1HMu4aX+/ovqsnmKeLtk0By0t3g=@vger.kernel.org X-Gm-Message-State: AOJu0YzsdPj3E+eCTjD2Al4s8ZYuc1J6AcVvJ+zApVvCKUq37zgEKCJv SCcmz9Jc3Nxr05BHEU9NePxz+vhrUP9iM7xd/ad8JIxNSXoveIiptXcqJhPUtA== X-Gm-Gg: AR+sD12KGsBk5F1ict9Uo5rTxPrEuI83orhiH+Pi/JWpBE2hAUp+uCmiKkuclrt1HNo Lrl3myHjxviS773H4LTn7QIEK+PzR/hcIeOq+2URdA4cPnprFXfM62ebePD20mPgQnFM5dDvplk 41j+Fsi8cvy4s+XQQyq+0z5jcgFY9Zn1xIc8gjKU+VPTBJXZATKVnHTUK2qN5Y6kOfDxxf+LYX+ iMiJrYcR9QCBowIcQE6HBAn9eZVlGb+w6fFbb057RthIiVgNAq6idbG9rLm3GjyMLfnqxn3uUDW v7E00inmAXMG+g1QvnJ8jCjAm9WDZCKDzwz/ax+hj+hMZZ7QhGOG22taV5nIc5JNea43EomCUei PcYKmsz/Bp7BZAgPwP1w/1krWygvbDc3P9rZC05+6c2qAmakMhYuupFx4ilzSHQfr5AE8yXnHMv 2d++G8e/qz2gi7Luc3aog7ovmqBoCvxZYEOJ8u X-Received: by 2002:a17:90a:d405:b0:38e:712a:bb38 with SMTP id 98e67ed59e1d1-38e712ac393mr7122237a91.24.1784557040181; Mon, 20 Jul 2026 07:17:20 -0700 (PDT) Received: from carrot.home.local (madb688455.ap.nuro.jp. [219.104.132.85]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38e4b247f1bsm6076027a91.17.2026.07.20.07.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 07:17:19 -0700 (PDT) From: Ryusuke Konishi To: Viacheslav Dubeyko Cc: linux-nilfs , LKML , syzbot+8baf9a79a3ffc6271cb6@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com Subject: [PATCH] nilfs2: fix BUG in nilfs_copy_dirty_pages() on dirty state mismatch Date: Mon, 20 Jul 2026 23:16:52 +0900 Message-ID: <20260720141716.205384-1-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Syzbot reported a kernel BUG triggered within nilfs_copy_dirty_pages(), which copies dirty DAT file folios/pages to its shadow page cache. The BUG occurs when a retrieved dirty folio/page unexpectedly loses its 'dirty' status. This issue arises because, since the commit referenced below, the 'dirty' flag of a folio/page can be cleared asynchronously after the filesystem detects metadata corruption and transitions to read-only mode. Resolve the issue by returning an -EROFS error if the filesystem has transitioned to read-only mode. Also change the behavior to issue a kernel warning only once instead of triggering a kernel BUG when this unexpected 'dirty' state is detected while the filesystem is not in read-only mode. Reported-by: syzbot+8baf9a79a3ffc6271cb6@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D8baf9a79a3ffc6271cb6 Fixes: 8c26c4e2694a ("nilfs2: fix issue with flush kernel thread after remo= unt in RO mode because of driver's internal error or metadata corruption") Signed-off-by: Ryusuke Konishi --- Viacheslav, please apply this for the next cycle. This fixes an issue reported by syzbot where a kernel BUG could be triggered depending on timing after filesystem corruption is detected. Thanks, Ryusuke Konishi fs/nilfs2/page.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index a9d8aa65416f..1d00bce21c37 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -243,6 +243,7 @@ static void nilfs_copy_folio(struct folio *dst, struct = folio *src, int nilfs_copy_dirty_pages(struct address_space *dmap, struct address_space *smap) { + struct inode *smap_inode =3D smap->host; struct folio_batch fbatch; unsigned int i; pgoff_t index =3D 0; @@ -258,8 +259,19 @@ int nilfs_copy_dirty_pages(struct address_space *dmap, struct folio *folio =3D fbatch.folios[i], *dfolio; =20 folio_lock(folio); - if (unlikely(!folio_test_dirty(folio))) - NILFS_FOLIO_BUG(folio, "inconsistent dirty state"); + if (unlikely(!folio_test_dirty(folio))) { + if (WARN_ONCE(!sb_rdonly(smap_inode->i_sb), + "inconsistent dirty state\n")) + goto unlock_folio; + + /* + * If the filesystem has been forced to read-only + * due to metadata corruption. + */ + folio_unlock(folio); + err =3D -EROFS; + break; + } =20 dfolio =3D filemap_grab_folio(dmap, folio->index); if (IS_ERR(dfolio)) { @@ -277,6 +289,7 @@ int nilfs_copy_dirty_pages(struct address_space *dmap, =20 folio_unlock(dfolio); folio_put(dfolio); +unlock_folio: folio_unlock(folio); } folio_batch_release(&fbatch); --=20 2.43.0