[PATCH v2] ntfs: guard the final LZNT1 sub-block header read
From: shaos
Date: Wed Nov 25 2026 - 03:50:42 EST
The legacy NTFS LZNT1 decompressor reads a 16-bit sub-block header
before checking that the full header remains in the compression
buffer. If only one byte remains, the read crosses the end of the
64 KiB buffer.
Return -EOVERFLOW for an incomplete header while preserving successful
termination when the buffer is exactly exhausted. Validate phrase-token
length against the sub-block boundary before reading it.
Tested on x86-64 with QEMU. The original header-boundary reproducer
and a phrase-token boundary reproducer no longer fault; both malformed
streams are rejected with -EOVERFLOW. The one-byte control still
returns byte 'A'.
Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Signed-off-by: shaos <shawnq1@xxxxxxx>
---
fs/ntfs/compress.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 82c7c7d290737..c7c520d31c53d 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -200,10 +200,11 @@ do_next_sb:
cb - cb_start);
/*
* Have we reached the end of the compression block or the end of the
- * decompressed data? The latter can happen for example if the current
- * position in the compression block is one byte before its end so the
- * first two checks do not detect it.
+ * decompressed data?
*/
+ if (cb != cb_end && cb_end - cb < sizeof(__le16))
+ goto return_overflow;
+
if (cb == cb_end || !le16_to_cpup((__le16 *)cb) ||
(*dest_index == dest_max_index &&
*dest_ofs == dest_max_ofs)) {
@@ -384,6 +385,10 @@ do_next_tag:
for (i = *dest_ofs - do_sb_start - 1; i >= 0x10; i >>= 1)
lg++;
+ /* Make sure the phrase token is fully within the sub-block. */
+ if (cb_sb_end - cb < sizeof(__le16))
+ goto return_overflow;
+
/* Get the phrase token into i. */
pt = le16_to_cpup((__le16 *)cb);
--
2.34.1