From: David Lee <david.lee@trailofbits.com>
To: shaggy@kernel.org
Cc: David Lee <david.lee@trailofbits.com>,
Kyle Zeng <kylebot@openai.com>,
Dominik 'Disconnect3d' Czarnota
<dominik.czarnota@trailofbits.com>,
jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH] jfs: pin metapage during synchronous writeback
Date: Fri, 31 Jul 2026 11:00:06 +0000 [thread overview]
Message-ID: <20260731110008.543282-1-david.lee@trailofbits.com> (raw)
release_metapage() decrements mp->count from one to zero but keeps the
struct metapage pointer in its local variable mp. For synchronous
writeback, release_metapage() calls metapage_write_one(), which in turn
calls metapage_write_folio(). metapage_write_folio() clears
META_dirty, submits the I/O, and this unlocks the folio while synchronous
I/O is in progress.
After writeback completes, kswapd can acquire the folio lock before
release_metapage(). metapage_release_folio() then sees mp->count == 0
and META_dirty clear, removes mp from the folio, and frees the struct
metapage. release_metapage() subsequently reacquires the folio lock
and passes its now-dangling mp pointer to drop_metapage(), which does
an use-after-free read of mp->count.
Increment mp->count before calling metapage_write_one(), and decrement
it only after release_metapage() has reacquired the folio lock. The
nonzero count makes metapage_release_folio() leave the struct metapage
allocated throughout the unlocked writeback interval. Once
release_metapage() holds the folio lock again, it can drop the temporary
reference and safely finish using mp.
Bug found and triaged by OpenAI Security Research and
validated by Trail of Bits.
Assisted-by: Codex:gpt-5.6-sol gpt-5.5-cyber
Signed-off-by: Kyle Zeng <kylebot@openai.com>
---
Trail of Bits has a reproducer for this bug that triggers a KASAN use-after-free and can share if needed.
fs/jfs/jfs_metapage.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 41fe12e641ce..d1962a44125a 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -882,9 +882,12 @@ void release_metapage(struct metapage * mp)
folio_mark_dirty(folio);
if (test_bit(META_sync, &mp->flag)) {
clear_bit(META_sync, &mp->flag);
+ /* Pin mp while metapage_write_one() drops the folio lock. */
+ mp->count++;
if (metapage_write_one(folio))
jfs_error(mp->sb, "metapage_write_one() failed\n");
folio_lock(folio);
+ mp->count--;
}
} else if (mp->lsn) /* discard_metapage doesn't remove it */
remove_from_logsync(mp);
--
2.53.0
next reply other threads:[~2026-07-31 11:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 11:00 David Lee [this message]
2026-08-02 8:33 ` Sven Eckelmann
2026-09-22 11:07 Bruno Produit
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=20260731110008.543282-1-david.lee@trailofbits.com \
--to=david.lee@trailofbits.com \
--cc=dominik.czarnota@trailofbits.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=kylebot@openai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shaggy@kernel.org \
/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®