From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
zhanxusheng@xiaomi.com, stable@vger.kernel.org
Subject: [PATCH] fs/ntfs3: don't write a compressed frame after a short copy
Date: Fri, 6 Nov 2026 21:49:05 +0800 [thread overview]
Message-ID: <20261106134906.3139994-1-zhanxusheng1024@gmail.com> (raw)
From: Zhan Xusheng <zhanxusheng@xiaomi.com>
ntfs_compress_write() skips ni_read_frame() when the write covers the
whole frame, or runs from the start of the frame to past i_size. If
the copy from user space then comes up short, the rest of the frame
is whatever the folios held; ni_write_frame() compresses it to disk
and the folios are marked uptodate.
The copy can come up short after fault_in_iov_iter_readable() has
succeeded if the source buffer is unmapped in between. On a volume
with 4K clusters, writing 64K at offset 0 of a compressed file while
another thread unmaps and remaps the last page of the buffer replaces
the last 4096 bytes of the frame with zeros. The write returns
-EFAULT.
Don't write the frame in that case; fail with -EFAULT as if nothing
had been copied.
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
Tested in QEMU on v7.4-rc1 with KASAN, page cache dropped before each
write:
before: 3 of 755 writes left zeros at bytes 61440-65535
after: 0 of 821 writes changed the file on failure
fs/ntfs3/file.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
index 1624f9b014e0..b1b925f95b8d 100644
--- a/fs/ntfs3/file.c
+++ b/fs/ntfs3/file.c
@@ -1099,7 +1099,8 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
/* Copy user data [pos : pos + count). */
while (count) {
- size_t copied, bytes;
+ size_t copied, bytes, want;
+ bool full_frame = false;
off = pos & (frame_size - 1);
bytes = frame_size - off;
@@ -1135,10 +1136,13 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
}
goto out;
}
+ } else {
+ full_frame = true;
}
}
WARN_ON(!bytes);
+ want = bytes;
copied = 0;
ip = off >> PAGE_SHIFT;
off = offset_in_page(pos);
@@ -1165,6 +1169,23 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
}
}
+ /*
+ * A fully overwritten frame was not read in, so after a short
+ * copy the rest of it holds whatever the folios contained.
+ * Don't write that out.
+ */
+ if (full_frame && copied < want) {
+ iov_iter_revert(from, copied);
+ for (ip = 0; ip < pages_per_frame; ip++) {
+ folio = page_folio(pages[ip]);
+ folio_clear_uptodate(folio);
+ folio_unlock(folio);
+ folio_put(folio);
+ }
+ err = -EFAULT;
+ goto out;
+ }
+
ni_lock(ni);
err = ni_write_frame(ni, pages, pages_per_frame);
ni_unlock(ni);
base-commit: f66469d9905b39d2c260a15d7d6db450f4db67c1
--
2.43.0
reply other threads:[~2026-11-06 13:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261106134906.3139994-1-zhanxusheng1024@gmail.com \
--to=zhanxusheng1024@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=zhanxusheng@xiaomi.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®