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

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