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 2/3] ntfs: fix premature page completion for sub-page compression blocks
Date: Thu,  3 Dec 2026 14:30:08 +0900	[thread overview]
Message-ID: <20261203053010.1836576-2-hyc.lee@gmail.com> (raw)
In-Reply-To: <20261203053010.1836576-1-hyc.lee@gmail.com>

With a compression block smaller than a page, cb_max_page is already
zero when the sparse and uncompressed paths decrement it to exclude
the partial end page, and the wrap makes the unsigned loop process
the whole page: pages are completed early or stale buffer contents
are copied into the page cache, so later blocks lose their output.
Only decrement cb_max_page when a full page precedes the partial one.

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 | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index d08abde85f58..1ebe1fe478f2 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -696,7 +696,8 @@ int ntfs_read_compressed_block(struct folio *folio)
 		ntfs_debug("Found sparse compression block.");
 		/* We can sleep from now on, so we drop lock. */
 		mutex_unlock(&ntfs_cb_lock);
-		if (cb_max_ofs)
+		/* cb_max_page can already be zero when the cb is smaller than a page. */
+		if (cb_max_ofs && cb_max_page)
 			cb_max_page--;
 		for (; cur_page < cb_max_page; cur_page++) {
 			page = pages[cur_page];
@@ -734,7 +735,8 @@ int ntfs_read_compressed_block(struct folio *folio)
 
 		ntfs_debug("Found uncompressed compression block.");
 		/* Uncompressed cb, copy it to the destination pages. */
-		if (cb_max_ofs)
+		/* See the sparse cb case above for the cb_max_page guard. */
+		if (cb_max_ofs && cb_max_page)
 			cb_max_page--;
 		/* First stage: copy data into destination pages. */
 		for (; cur_page < cb_max_page; cur_page++) {
-- 
2.43.0


      reply	other threads:[~2026-12-03  5:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  5:30 [PATCH 1/3] ntfs: bound LZNT1 input to the bytes actually filled Hyunchul Lee
2026-12-03  5:30 ` 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=20261203053010.1836576-2-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