* [PATCH 1/4] ntfs: validate phrase output before advancing
@ 2026-12-04 5:54 Hyunchul Lee
2026-12-04 5:54 ` [PATCH 2/4] ntfs: stop processing after a decompression failure Hyunchul Lee
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Hyunchul Lee @ 2026-12-04 5:54 UTC (permalink / raw)
To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable
The LZNT1 phrase-token path advanced *dest_ofs before checking that the
result fit in the current sub-block. On malformed input,
ntfs_decompress() therefore returned with the caller's cur_ofs beyond
the failed sub-block even though no phrase bytes had been copied.
Check the phrase length against the sub-block bound first, copy it, and
update *dest_ofs only after the copy succeeds, so a failure never leaves
the destination position past the failed sub-block.
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 | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 2f11206b7428..86381ca2b878 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -408,9 +408,8 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],
/* Now calculate the length of the byte sequence. */
length = (pt & (0xfff >> lg)) + 3;
- /* Advance destination position and verify it is in range. */
- *dest_ofs += length;
- if (*dest_ofs > do_sb_end)
+ /* Verify destination is in range. */
+ if (*dest_ofs + length > do_sb_end)
goto return_overflow;
/* The number of non-overlapping bytes. */
@@ -432,11 +431,14 @@ static int ntfs_decompress(struct page *dest_pages[], int completed_pages[],
memcpy(dp_addr, dp_back_addr, max_non_overlap);
dp_addr += max_non_overlap;
dp_back_addr += max_non_overlap;
- length -= max_non_overlap;
- while (length--)
+ i = length - max_non_overlap;
+ while (i--)
*dp_addr++ = *dp_back_addr++;
}
+ /* Advance destination offset after the copy succeeds. */
+ *dest_ofs += length;
+
/* Advance source position and continue with the next token. */
cb += 2;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/4] ntfs: stop processing after a decompression failure
2026-12-04 5:54 [PATCH 1/4] ntfs: validate phrase output before advancing Hyunchul Lee
@ 2026-12-04 5:54 ` Hyunchul Lee
2026-12-04 5:54 ` [PATCH 3/4] ntfs: zero hole-filled pages above initialized_size Hyunchul Lee
2026-12-04 5:54 ` [PATCH 4/4] ntfs: treat compression blocks beyond EOF as sparse Hyunchul Lee
2 siblings, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2026-12-04 5:54 UTC (permalink / raw)
To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable
After a decompression failure, ntfs_read_compressed_block() logged
"Skipping this compression block." and continued to the next block
with "if (nr_cbs) goto do_next_cb;" using the callee-updated
cur_page/cur_ofs. These describe the failure point inside the failed
block, not the next block's own start, so every remaining block would
be processed shifted backward and the unwritten tail of the failed
block would never be filled.
With cb_size < PAGE_SIZE, the only case with more than one block, the
whole read covers the single page containing the failed block, so the
page can never complete and processing the rest is wasted work.
Stop the read (nr_cbs = 0), let the existing release loop free the
unfinished pages, and return the decompression error. This also
stops the read for any error exit that may be added to
ntfs_decompress() in the future.
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 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 86381ca2b878..eb2538b4c713 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -804,7 +804,7 @@ int ntfs_read_compressed_block(struct folio *folio)
*/
if (err) {
ntfs_error(vol->sb,
- "ntfs_decompress() failed in inode 0x%llx with error code %i. Skipping this compression block.",
+ "ntfs_decompress() failed in inode 0x%llx with error code %i.",
ni->mft_no, -err);
/* Release the unfinished pages. */
for (; prev_cur_page < cur_page; prev_cur_page++) {
@@ -817,6 +817,7 @@ int ntfs_read_compressed_block(struct folio *folio)
pages[prev_cur_page] = NULL;
}
}
+ nr_cbs = 0;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/4] ntfs: zero hole-filled pages above initialized_size
2026-12-04 5:54 [PATCH 1/4] ntfs: validate phrase output before advancing Hyunchul Lee
2026-12-04 5:54 ` [PATCH 2/4] ntfs: stop processing after a decompression failure Hyunchul Lee
@ 2026-12-04 5:54 ` Hyunchul Lee
2026-12-04 5:54 ` [PATCH 4/4] ntfs: treat compression blocks beyond EOF as sparse Hyunchul Lee
2 siblings, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2026-12-04 5:54 UTC (permalink / raw)
To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable
The sparse, hole-filled full-page path is the only page completion path
that never calls handle_bounds_compressed_page().
The omission is exposed when cb_size < PAGE_SIZE: an earlier compression
block in the same page can fill bytes above initialized_size, and a
following sparse block then completes the page and marks it Uptodate.
With initialized_size < i_size, those bytes surface as live data instead
of zeros when the page is read back.
Call handle_bounds_compressed_page() on the sparse path as well, so
that bytes above initialized_size are zeroed before the completed page
is marked Uptodate.
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 | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index eb2538b4c713..b3fb72761c6b 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -709,6 +709,8 @@ int ntfs_read_compressed_block(struct folio *folio)
page = pages[cur_page];
if (page) {
memzero_page(page, cur_ofs, PAGE_SIZE - cur_ofs);
+ handle_bounds_compressed_page(page, i_size,
+ initialized_size);
SetPageUptodate(page);
unlock_page(page);
if (cur_page == xpage)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/4] ntfs: treat compression blocks beyond EOF as sparse
2026-12-04 5:54 [PATCH 1/4] ntfs: validate phrase output before advancing Hyunchul Lee
2026-12-04 5:54 ` [PATCH 2/4] ntfs: stop processing after a decompression failure Hyunchul Lee
2026-12-04 5:54 ` [PATCH 3/4] ntfs: zero hole-filled pages above initialized_size Hyunchul Lee
@ 2026-12-04 5:54 ` Hyunchul Lee
2 siblings, 0 replies; 4+ messages in thread
From: Hyunchul Lee @ 2026-12-04 5:54 UTC (permalink / raw)
To: Namjae Jeon; +Cc: Hyunchul Lee, Baolin Liu, ntfs, stable
nr_cbs is derived from the page range and ignores i_size, while a
compressed file is only allocated up to round_up(i_size, cb_size).
The runlist walk for such a block reaches the LCN_ENOENT terminator
and the read fails with -EIO. Every compressed file whose
round_up(i_size, cb_size) is not a multiple of PAGE_SIZE fails to read
its last page whenever PAGE_SIZE > cb_size.
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 | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index b3fb72761c6b..375c49949ce1 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -609,8 +609,15 @@ int ntfs_read_compressed_block(struct folio *folio)
cb_end = cb + cb_size;
rl = NULL;
- for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn;
- vcn++) {
+ vcn = start_vcn;
+ start_vcn += cb_clusters;
+ /*
+ * A cb starting at or after EOF may be unallocated, so treat it
+ * as sparse rather than failing the runlist lookup below.
+ */
+ if (ntfs_cluster_to_bytes(vol, vcn) >= i_size)
+ goto sparse_cb;
+ for (; vcn < start_vcn; vcn++) {
bool is_retry = false;
if (!rl) {
@@ -669,6 +676,7 @@ int ntfs_read_compressed_block(struct folio *folio)
cb_pos += vol->cluster_size;
}
+sparse_cb:
/* Release the lock if we took it. */
if (rl)
up_read(&ni->runlist.lock);
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 5:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 5:54 [PATCH 1/4] ntfs: validate phrase output before advancing Hyunchul Lee
2026-12-04 5:54 ` [PATCH 2/4] ntfs: stop processing after a decompression failure Hyunchul Lee
2026-12-04 5:54 ` [PATCH 3/4] ntfs: zero hole-filled pages above initialized_size Hyunchul Lee
2026-12-04 5:54 ` [PATCH 4/4] ntfs: treat compression blocks beyond EOF as sparse Hyunchul Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox