Re: [PATCH 6/6] ntfs: read initialized_size under size_lock in the mmap prepare path
From: liubaolin
Date: Wed Nov 25 2026 - 09:11:01 EST
在 2026/11/25 15:35, Hongling Zeng 写道:
ntfs_file_mmap_prepare() reads ni->initialized_size without the
size lock when deciding whether a shared writable mapping needs
its initialized size extended before the faults start. The field
is published under size_lock, so the read is a data race on the
protocol the other readers follow: a stale low value causes a
redundant call that __ntfs_extend_initialized_size() re-checks
under the lock, and a stale high value skips the extension and
leaves it to the write faults.
Take the snapshot under size_lock like the other readers.
Fixes: 9c87959601e8 ("ntfs: update file operations")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hongling Zeng <zenghongling@xxxxxxxxxx>
---
fs/ntfs/file.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 70a86d6fee6b..1f08fe679a86 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -1044,14 +1044,20 @@ int ntfs_file_mmap_prepare(struct vm_area_desc *desc)
if (vma_desc_test_all(desc, VMA_SHARED_BIT, VMA_MAYWRITE_BIT)) {
struct inode *inode = file_inode(file);
+ struct ntfs_inode *ni = NTFS_I(inode);
loff_t from, to;
+ loff_t initialized_size;
+ unsigned long flags;
int err;
from = ((loff_t)desc->pgoff << PAGE_SHIFT);
to = min_t(loff_t, i_size_read(inode),
from + desc->end - desc->start);
- if (NTFS_I(inode)->initialized_size < to) {
+ read_lock_irqsave(&ni->size_lock, flags);
+ initialized_size = ni->initialized_size;
+ read_unlock_irqrestore(&ni->size_lock, flags);
+ if (initialized_size < to) {
err = ntfs_extend_initialized_size(inode, to, to);
if (err)
return err;
Looks good to me.
Reviewed-by: Baolin Liu <liubaolin@xxxxxxxxxx>