Linux filesystem development
 help / color / mirror / Atom feed
From: Senjin <senjin@hatchling.org>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: Senjin <senjin@hatchling.org>,
	ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 2/2] fs/ntfs3: don't mark pages uptodate when ni_read_frame() fails
Date: 21 Oct 2026 04:58:39 -0000	[thread overview]
Message-ID: <6ad8467f30bcfe9e100d3b06@mailersend.net> (raw)
In-Reply-To: <20261021045734.573753-1-senjin@hatchling.org>

ni_read_frame() calls SetPageUptodate() on every page of the frame on
exit, including when reading or decompressing the frame failed. The
pages then hold zeroes or partially decompressed data, and that is
served as valid file data until the page cache is dropped.

The error is also lost for the folio that was actually requested:
ni_read_folio_cmpr() returns it from ->read_folio, but
filemap_read_folio() only checks folio_test_uptodate() afterwards and
treats the read as successful. Userspace gets wrong data, read() returns
no error, and nothing is logged.

Only mark the pages uptodate when the frame was read successfully. On
failure the requested folio is left !uptodate and the read returns an
error; the other pages of the frame are retried on their next access.

With the bug fixed by the previous patch still present, a read of an
affected file now fails with an error after the last good frame, instead
of silently returning zeroes.

Fixes: f35590ee26f5 ("fs/ntfs3: remove ntfs_bio_pages and use page cache for compressed I/O")
Cc: stable@vger.kernel.org # 6.19+
Signed-off-by: Senjin <senjin@hatchling.org>
---
 fs/ntfs3/frecord.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index bead01a..a8b696d 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -2287,7 +2287,6 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
 	u64 vbo_disk;
 	size_t unc_size = 0;
 	u32 frame_size, i, ondisk_size;
-	struct page *pg;
 	struct ATTRIB *attr;
 	CLST frame, clst_data;
 
@@ -2519,9 +2518,14 @@ out1:
 #endif
 	vunmap(frame_mem);
 out:
-	for (i = 0; i < pages_per_frame; i++) {
-		pg = pages[i];
-		SetPageUptodate(pg);
+	/*
+	 * Only mark the pages uptodate if the frame was read successfully,
+	 * otherwise zeroed or partially decompressed pages would be served
+	 * from the page cache as valid data.
+	 */
+	if (!err) {
+		for (i = 0; i < pages_per_frame; i++)
+			SetPageUptodate(pages[i]);
 	}
 
 	return err;
-- 
2.56.0

      parent reply	other threads:[~2026-10-21  4:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261021045734.573753-1-senjin@hatchling.org>
2026-10-21  4:58 ` [PATCH 1/2] fs/ntfs3: map the right page of large folios in ntfs_read_write_run() Senjin
2026-10-21  4:58 ` Senjin [this message]

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=6ad8467f30bcfe9e100d3b06@mailersend.net \
    --to=senjin@hatchling.org \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /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