Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Hyunchul Lee <hyc.lee@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>,
	Baolin Liu <liubaolin@kylinos.cn>,
	ntfs@lists.linux.dev, stable@vger.kernel.org
Subject: [PATCH 4/4] ntfs: treat compression blocks beyond EOF as sparse
Date: Fri,  4 Dec 2026 14:54:42 +0900	[thread overview]
Message-ID: <20261204055442.3619912-4-hyc.lee@gmail.com> (raw)
In-Reply-To: <20261204055442.3619912-1-hyc.lee@gmail.com>

nr_cbs is derived from the page range and ignores i_size, while a
compressed file is only allocated up to round_up(i_size, cb_size).

The runlist walk for such a block reaches the LCN_ENOENT terminator
and the read fails with -EIO. Every compressed file whose
round_up(i_size, cb_size) is not a multiple of PAGE_SIZE fails to read
its last page whenever PAGE_SIZE > cb_size.

Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
---
 fs/ntfs/compress.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index b3fb72761c6b..375c49949ce1 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -609,8 +609,15 @@ int ntfs_read_compressed_block(struct folio *folio)
 	cb_end = cb + cb_size;
 
 	rl = NULL;
-	for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn;
-			vcn++) {
+	vcn = start_vcn;
+	start_vcn += cb_clusters;
+	/*
+	 * A cb starting at or after EOF may be unallocated, so treat it
+	 * as sparse rather than failing the runlist lookup below.
+	 */
+	if (ntfs_cluster_to_bytes(vol, vcn) >= i_size)
+		goto sparse_cb;
+	for (; vcn < start_vcn; vcn++) {
 		bool is_retry = false;
 
 		if (!rl) {
@@ -669,6 +676,7 @@ int ntfs_read_compressed_block(struct folio *folio)
 		cb_pos += vol->cluster_size;
 	}
 
+sparse_cb:
 	/* Release the lock if we took it. */
 	if (rl)
 		up_read(&ni->runlist.lock);
-- 
2.43.0


      parent reply	other threads:[~2026-12-04  5:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  5:54 [PATCH 1/4] ntfs: validate phrase output before advancing Hyunchul Lee
2026-12-04  5:54 ` [PATCH 2/4] ntfs: stop processing after a decompression failure Hyunchul Lee
2026-12-04  5:54 ` [PATCH 3/4] ntfs: zero hole-filled pages above initialized_size Hyunchul Lee
2026-12-04  5:54 ` Hyunchul Lee [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=20261204055442.3619912-4-hyc.lee@gmail.com \
    --to=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=liubaolin@kylinos.cn \
    --cc=ntfs@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