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 1/3] ntfs: bound LZNT1 input to the bytes actually filled
Date: Thu,  3 Dec 2026 14:30:07 +0900	[thread overview]
Message-ID: <20261203053010.1836576-1-hyc.lee@gmail.com> (raw)

The decompressor is handed the full cb_size although only the filled
data plus the two-byte terminator is valid, so a corrupted sub-block
length can make it consume stale bytes from the shared compression
buffer into the page cache. Bound the input to the bytes actually
filled, including the terminator when present.

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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index c7c520d31c53..d08abde85f58 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -477,6 +477,7 @@ int ntfs_read_compressed_block(struct folio *folio)
 	struct runlist_element *rl;
 	unsigned long flags;
 	u8 *cb, *cb_pos, *cb_end;
+	u32 cb_filled;
 	unsigned long offset, index = folio->index;
 	u32 cb_size = ni->itype.compressed.block_size;
 	u64 cb_size_mask = cb_size - 1UL;
@@ -670,6 +671,11 @@ int ntfs_read_compressed_block(struct folio *folio)
 	if (cb_pos + 2 <= cb + cb_size)
 		*(u16 *)cb_pos = 0;
 
+	/* Valid input is only the filled data plus the terminator, if any. */
+	cb_filled = cb_pos - cb;
+	if (cb_pos + 2 <= cb + cb_size)
+		cb_filled += 2;
+
 	/* Reset cb_pos back to the beginning. */
 	cb_pos = cb;
 
@@ -782,7 +788,7 @@ int ntfs_read_compressed_block(struct folio *folio)
 		ntfs_debug("Found compressed compression block.");
 		err = ntfs_lznt1_codec_ops.decompress_pages(pages, completed_pages, &cur_page,
 				&cur_ofs, cb_max_page, cb_max_ofs, xpage,
-				&xpage_done, cb_pos, cb_size - (cb_pos - cb),
+				&xpage_done, cb_pos, cb_filled,
 				i_size, initialized_size);
 		/*
 		 * We can sleep from now on, lock already dropped by
-- 
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 Hyunchul Lee [this message]
2026-12-03  5:30 ` [PATCH 2/3] ntfs: fix premature page completion for sub-page compression blocks Hyunchul Lee

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-1-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