From: Jan Kara <jack@suse.cz>
To: <linux-fsdevel@vger.kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
aivazian.tigran@gmail.com, Ted Tso <tytso@mit.edu>,
<linux-ext4@vger.kernel.org>,
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
Jan Kara <jack@suse.cz>, Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH v5 02/20] fs: Fix possible UAF in mark_buffer_write_io_error()
Date: Mon, 27 Jul 2026 12:49:20 +0200 [thread overview]
Message-ID: <20260727104923.3828017-22-jack@suse.cz> (raw)
In-Reply-To: <20260727101509.21667-1-jack@suse.cz>
When filesystem is freeing inode it calls mmb_invalidate() which removes
bhs from inode's metadata bh tracking and clears b_mmb for them. However
if the inode is getting deleted, we don't bother with calling mmb_sync()
before and thus these buffers can be under IO and we can be racing with
IO completion handler calling mark_buffer_write_io_error(). This race
can lead to mark_buffer_write_io_error() either hitting NULL pointer
reference or trying to operate on already freed inode. Protect the
mapping handling with RCU to make sure mmb and inode aren't freed before
we are done with them.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/buffer.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 9af5f061a1f8..daaa6614a6d6 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1123,12 +1123,18 @@ EXPORT_SYMBOL(mark_buffer_dirty);
void mark_buffer_write_io_error(struct buffer_head *bh)
{
+ struct mapping_metadata_bhs *mmb;
+
set_buffer_write_io_error(bh);
/* FIXME: do we need to set this in both places? */
if (bh->b_folio && bh->b_folio->mapping)
mapping_set_error(bh->b_folio->mapping, -EIO);
- if (bh->b_mmb)
- mapping_set_error(bh->b_mmb->mapping, -EIO);
+ /* Protect us from mmb & inode getting freed while we work on it */
+ rcu_read_lock();
+ mmb = READ_ONCE(bh->b_mmb);
+ if (mmb)
+ mapping_set_error(mmb->mapping, -EIO);
+ rcu_read_unlock();
}
EXPORT_SYMBOL(mark_buffer_write_io_error);
--
2.51.0
next prev parent reply other threads:[~2026-07-27 10:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 10:49 [PATCH v5 0/20] fs: Fix missed inode write during fsync Jan Kara
2026-07-27 10:49 ` [PATCH v5 01/20] affs: Drop support for metadata bh tracking Jan Kara
2026-07-27 10:49 ` Jan Kara [this message]
2026-07-27 10:49 ` [PATCH v5 03/20] fs: Fix missed inode writeback when racing with __writeback_single_inode Jan Kara
2026-07-27 10:49 ` [PATCH v5 04/20] ext4: Allocate mapping_metadata_bhs struct on demand Jan Kara
2026-07-27 10:49 ` [PATCH v5 05/20] fs: Provide way for filesystem to wait for metadata writeback Jan Kara
2026-07-27 10:49 ` [PATCH v5 06/20] ext2: Fix lost inode updates for IS_SYNC inodes Jan Kara
2026-07-27 10:49 ` [PATCH v5 07/20] ext2: Drop __ext2_write_inode() Jan Kara
2026-07-27 10:49 ` [PATCH v5 08/20] ext2: Avoid unnecessary inode buffer writeback for sync(2) Jan Kara
2026-07-27 10:49 ` [PATCH v5 09/20] ext2: Fix data integrity writeout issues Jan Kara
2026-07-27 10:49 ` [PATCH v5 10/20] udf: " Jan Kara
2026-07-27 10:49 ` [PATCH v5 11/20] udf: Use sync_inode_metadata() to writeout IS_SYNC inode Jan Kara
2026-07-27 10:49 ` [PATCH v5 12/20] udf: Drop udf_sync_inode() Jan Kara
2026-07-27 10:49 ` [PATCH v5 13/20] udf: Use sync_inode_metadata() in udf_evict_inode() Jan Kara
2026-07-27 10:49 ` [PATCH v5 14/20] udf: Fold udf_update_inode() into udf_write_inode() Jan Kara
2026-07-27 10:49 ` [PATCH v5 15/20] bfs: Fix data integrity writeout issues Jan Kara
2026-07-27 10:49 ` [PATCH v5 16/20] minix: " Jan Kara
2026-07-27 10:49 ` [PATCH v5 17/20] ext4: Fix data integrity writeout issues in nojournal mode Jan Kara
2026-07-27 10:49 ` [PATCH v5 18/20] fat: Fix missed inode writeback during fsync(2) Jan Kara
2026-07-27 10:49 ` [PATCH v5 19/20] fat: Replace fat_sync_inode() with sync_inode_metadata() Jan Kara
2026-07-27 10:49 ` [PATCH v5 20/20] vfs: Remove mmb_fsync() Jan Kara
2026-07-27 15:51 ` [PATCH v5 0/20] fs: Fix missed inode write during fsync Christian Brauner
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=20260727104923.3828017-22-jack@suse.cz \
--to=jack@suse.cz \
--cc=aivazian.tigran@gmail.com \
--cc=brauner@kernel.org \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=tytso@mit.edu \
/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