Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/3] ntfs: bound LZNT1 input to the bytes actually filled
@ 2026-12-03  5:30 Hyunchul Lee
  2026-12-03  5:30 ` [PATCH 2/3] ntfs: fix premature page completion for sub-page compression blocks Hyunchul Lee
  0 siblings, 1 reply; 2+ messages in thread
From: Hyunchul Lee @ 2026-12-03  5:30 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/3] ntfs: fix premature page completion for sub-page compression blocks
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Hyunchul Lee @ 2026-12-03  5:30 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03  5:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  5:30 [PATCH 1/3] ntfs: bound LZNT1 input to the bytes actually filled Hyunchul Lee
2026-12-03  5:30 ` [PATCH 2/3] ntfs: fix premature page completion for sub-page compression blocks Hyunchul Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox