From: liubaolin <liubaolin12138@163.com>
To: Hongling Zeng <zenghongling@kylinos.cn>,
linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
zhongling0719@126.com, stable@vger.kernel.org
Subject: Re: [PATCH 5/6] ntfs: serialize the mmap write fault initialized size update
Date: Wed, 25 Nov 2026 22:08:23 +0800 [thread overview]
Message-ID: <02126467-a189-4ed7-953a-3df80ab90754@163.com> (raw)
In-Reply-To: <20261125073547.154150-6-zenghongling@kylinos.cn>
在 2026/11/25 15:35, Hongling Zeng 写道:
> The mmap write fault path checks whether the faulting range extends
> past ni->initialized_size with an unlocked read and then calls
> ntfs_attr_set_initialized_size(), which rewrites the field and the
> MFT record with its argument unconditionally. The call is made
> without the MFT record lock that every other caller of the function
> holds, and a buffered write or a second fault extending the
> initialized size between the read and the rewrite can make the
> rewrite shrink the field again, which exposes initialized data as
> uninitialized.
>
> Hold the MFT record lock across the check and the update and read
> initialized_size under size_lock inside the critical section, so the
> decision is made on the value that is current for the record and the
> field can no longer regress through the fault path.
>
> Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
> ---
> fs/ntfs/attrib.c | 1 +
> fs/ntfs/iomap.c | 15 +++++++++++----
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
> index 081ce3e829f2..56df3049a386 100644
> --- a/fs/ntfs/attrib.c
> +++ b/fs/ntfs/attrib.c
> @@ -2431,6 +2431,7 @@ int ntfs_attr_set(struct ntfs_inode *ni, s64 ofs, s64 cnt, const u8 val)
> return ret;
> }
>
> +/* The caller must hold the base inode's mft record lock. */
> int ntfs_attr_set_initialized_size(struct ntfs_inode *ni, loff_t new_size)
> {
> struct ntfs_attr_search_ctx *ctx;
> diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
> index afc4494822e1..39772e9e5f32 100644
> --- a/fs/ntfs/iomap.c
> +++ b/fs/ntfs/iomap.c
> @@ -676,10 +676,17 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode,
> return err;
> }
>
> - if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE &&
> - iomap->offset + iomap->length > ni->initialized_size) {
> - err = ntfs_attr_set_initialized_size(ni,
> - iomap->offset + iomap->length);
> + if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE) {
> + loff_t initialized_size;
> +
> + mutex_lock(&mrec_ni->mrec_lock);
> + read_lock_irqsave(&ni->size_lock, irqflags);
> + initialized_size = ni->initialized_size;
> + read_unlock_irqrestore(&ni->size_lock, irqflags);
> + if (iomap->offset + iomap->length > initialized_size)
> + err = ntfs_attr_set_initialized_size(ni,
> + iomap->offset + iomap->length);
> + mutex_unlock(&mrec_ni->mrec_lock);
> }
>
> return err;
Looks good to me.
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
next prev parent reply other threads:[~2026-11-25 14:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:35 [PATCH 0/6] ntfs: synchronize the in-memory size handling Hongling Zeng
2026-11-25 7:35 ` [PATCH 1/6] ntfs: mark the record dirtied by a resident write at iomap begin Hongling Zeng
2026-11-25 7:35 ` [PATCH 2/6] ntfs: roll back the size update when the attribute lookup fails Hongling Zeng
2026-11-25 14:05 ` liubaolin
2026-11-25 7:35 ` [PATCH 3/6] ntfs: read initialized_size under size_lock in the iomap paths Hongling Zeng
2026-11-25 14:07 ` liubaolin
2026-11-25 7:35 ` [PATCH 4/6] ntfs: update the in-memory sizes under the size lock Hongling Zeng
2026-11-25 14:08 ` liubaolin
2026-11-25 7:35 ` [PATCH 5/6] ntfs: serialize the mmap write fault initialized size update Hongling Zeng
2026-11-25 14:08 ` liubaolin [this message]
2026-11-25 7:35 ` [PATCH 6/6] ntfs: read initialized_size under size_lock in the mmap prepare path Hongling Zeng
2026-11-25 14:08 ` liubaolin
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=02126467-a189-4ed7-953a-3df80ab90754@163.com \
--to=liubaolin12138@163.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zenghongling@kylinos.cn \
--cc=zhongling0719@126.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®