From: "Darrick J. Wong" <djwong@kernel.org>
To: Deepanshu Kartikey <kartikey406@gmail.com>
Cc: tytso@mit.edu, adilger.kernel@dilger.ca,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+b0a0670332b6b3230a0a@syzkaller.appspotmail.com
Subject: Re: [PATCH] ext4: check folio uptodate state in ext4_page_mkwrite()
Date: Fri, 21 Nov 2025 08:27:32 -0800 [thread overview]
Message-ID: <20251121162732.GU196358@frogsfrogsfrogs> (raw)
In-Reply-To: <20251121131305.332698-1-kartikey406@gmail.com>
On Fri, Nov 21, 2025 at 06:43:05PM +0530, Deepanshu Kartikey wrote:
> When a write fault occurs on a memory-mapped ext4 file, ext4_page_mkwrite()
> is called to prepare the folio for writing. However, if the folio could
> not be read successfully due to filesystem corruption or I/O errors, it
> will not be marked uptodate.
>
> Attempting to write to a non-uptodate folio is problematic because:
> 1. We don't have valid data from the backing store to preserve
> 2. A subsequent writeback could write uninitialized data to disk
> 3. It triggers a warning in __folio_mark_dirty():
> WARN_ON_ONCE(warn && !folio_test_uptodate(folio))
> This issue can be reproduced by:
> 1. Creating a corrupted ext4 filesystem with invalid extent entries
> 2. Memory-mapping a file on that filesystem
> 3. Attempting to write to the mapped region
>
> The sequence of events is:
> - User accesses mmap region -> page fault
> - ext4_filemap_fault() -> ext4_map_blocks() detects corruption
^^^^^^^^^^^^^^^^^^ what function is this?
$ grep ext4_filemap_fault fs/ext4/
$
> - Returns error, folio allocated but NOT marked uptodate
> - User writes to same region -> ext4_page_mkwrite() called
> - Without check: folio marked dirty -> WARNING
> - With check: return VM_FAULT_SIGBUS immediately
Doesn't filemap_fault bring the contents into the folio and return
VM_FAULT_SIGBUS if that fails?
--D
>
> Fix this by checking folio_test_uptodate() early in ext4_page_mkwrite(),
> before any code paths (delalloc, journal data, or normal). This ensures
> all paths are protected. If the folio is not uptodate, unlock it and
> return VM_FAULT_SIGBUS to signal the error to userspace.
>
> Reported-by: syzbot+b0a0670332b6b3230a0a@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b0a0670332b6b3230a0a
> Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
> ---
> fs/ext4/inode.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index e99306a8f47c..18a029362c1f 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -6688,6 +6688,14 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf)
> if (err)
> goto out_ret;
>
> + folio_lock(folio);
> + if (!folio_test_uptodate(folio)) {
> + folio_unlock(folio);
> + ret = VM_FAULT_SIGBUS;
> + goto out;
> + }
> + folio_unlock(folio);
> +
> /*
> * On data journalling we skip straight to the transaction handle:
> * there's no delalloc; page truncated will be checked later; the
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2025-11-21 16:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 13:13 [PATCH] ext4: check folio uptodate state in ext4_page_mkwrite() Deepanshu Kartikey
2025-11-21 16:27 ` Darrick J. Wong [this message]
2025-11-21 16:49 ` Deepanshu Kartikey
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=20251121162732.GU196358@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=kartikey406@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+b0a0670332b6b3230a0a@syzkaller.appspotmail.com \
--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