From: Arbab Haider <arbabhaider649@gmail.com>
To: Dave Kleikamp <shaggy@kernel.org>
Cc: jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
syzbot+d7ffeb5538fe5c793f74@syzkaller.appspotmail.com,
stable@vger.kernel.org, Arbab Haider <arbabhaider649@gmail.com>
Subject: [PATCH] jfs: handle NULL folio->mapping in metapage_write_one() and release_metapage()
Date: Mon, 23 Nov 2026 00:57:58 +0500 [thread overview]
Message-ID: <20261122195758.32692-2-arbabhaider649@gmail.com> (raw)
syzbot reported a NULL pointer dereference in metapage_write_folio()
called from metapage_write_one() during lazy commit teardown:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: 0010:metapage_write_folio+0xa7/0xcf0 fs/jfs/jfs_metapage.c:428
Call Trace:
metapage_write_one+0x2c8/0x520 fs/jfs/jfs_metapage.c:818
release_metapage+0x5b9/0xab0 fs/jfs/jfs_metapage.c:884
txUnlock+0x509/0xdc0 fs/jfs/jfs_txnmgr.c:948
jfs_lazycommit+0x52c/0xa10 fs/jfs/jfs_txnmgr.c:2734
During unmount or inode eviction, truncate_inode_pages_final() can
remove a folio from its address_space (setting folio->mapping to NULL)
while jfsCommit still holds a reference to a dirty metapage on that
folio. When jfsCommit subsequently runs txUnlock() -> release_metapage():
1. If META_sync is set, metapage_write_one() proceeds with a NULL
mapping and calls metapage_write_folio(), which dereferences
folio->mapping->host (and filemap_check_errors(mapping) would also
dereference NULL).
2. If META_dirty is set without META_sync, folio_mark_dirty() is a
no-op on an unmapped folio, leaving META_dirty set and the metapage
stranded on log->synclist; drop_metapage() then skips freeing it and
jfs_flush_journal() stalls waiting for log->synclist to empty.
Fix both paths under the folio lock:
- In metapage_write_one(), if !mapping, clear META_dirty and call
remove_from_logsync() on any attached metapages, clear the folio
dirty state, unlock the folio, and return 0.
- In release_metapage(), if META_dirty is set on an unmapped folio,
clear META_dirty and META_sync and remove the metapage from logsync
so drop_metapage() can release it cleanly.
Tested locally in QEMU (x86_64, 4 CPUs, KASAN+UBSAN) using syzbot's C
reproducer with per-iteration mount namespaces: crashed in <1s before
the patch, and completed 56 mount/remount/unmount iterations in 15s
with zero hangs, KASAN, Oops, or synclist warnings after the patch.
Reported-by: syzbot+d7ffeb5538fe5c793f74@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d7ffeb5538fe5c793f74
Fixes: 35474d52c605 ("jfs: Convert metapage_writepage to metapage_write_folio")
Cc: stable@vger.kernel.org
Signed-off-by: Arbab Haider <arbabhaider649@gmail.com>
---
fs/jfs/jfs_metapage.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 41fe12e64..9df810c97 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -812,6 +812,23 @@ static int metapage_write_one(struct folio *folio)
BUG_ON(!folio_test_locked(folio));
+ if (unlikely(!mapping)) {
+ struct metapage *mp;
+ unsigned int offset;
+
+ for (offset = 0; offset < PAGE_SIZE; offset += PSIZE) {
+ mp = folio_to_mp(folio, offset);
+ if (!mp)
+ continue;
+ clear_bit(META_dirty, &mp->flag);
+ if (mp->lsn)
+ remove_from_logsync(mp);
+ }
+ folio_clear_dirty_for_io(folio);
+ folio_unlock(folio);
+ return 0;
+ }
+
folio_wait_writeback(folio);
if (folio_clear_dirty_for_io(folio)) {
@@ -879,12 +896,19 @@ void release_metapage(struct metapage * mp)
}
if (test_bit(META_dirty, &mp->flag)) {
- folio_mark_dirty(folio);
- if (test_bit(META_sync, &mp->flag)) {
+ if (unlikely(!folio->mapping)) {
+ clear_bit(META_dirty, &mp->flag);
clear_bit(META_sync, &mp->flag);
- if (metapage_write_one(folio))
- jfs_error(mp->sb, "metapage_write_one() failed\n");
- folio_lock(folio);
+ if (mp->lsn)
+ remove_from_logsync(mp);
+ } else {
+ folio_mark_dirty(folio);
+ if (test_bit(META_sync, &mp->flag)) {
+ clear_bit(META_sync, &mp->flag);
+ if (metapage_write_one(folio))
+ jfs_error(mp->sb, "metapage_write_one() failed\n");
+ folio_lock(folio);
+ }
}
} else if (mp->lsn) /* discard_metapage doesn't remove it */
remove_from_logsync(mp);
--
2.53.0
reply other threads:[~2026-11-22 19:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261122195758.32692-2-arbabhaider649@gmail.com \
--to=arbabhaider649@gmail.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=shaggy@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+d7ffeb5538fe5c793f74@syzkaller.appspotmail.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®