[PATCH] ntfs: guard the final LZNT1 sub-block header read
From: shaos
Date: Wed Nov 25 2026 - 00:17:48 EST
Hello,
The legacy NTFS LZNT1 decompressor reads a 16-bit sub-block header
before checking that two bytes remain in the compressed buffer. If
one byte remains, the read crosses the end of the 64 KiB
compression buffer. A crafted compressed file on an NTFS volume can
reproduce this as a kernel page fault while the file is read.
Check the remaining input length before dereferencing the header. This
preserves the existing end-of-buffer handling while avoiding the read
when fewer than two bytes remain.
HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4
compiler: gcc 11.4.0, GNU ld 2.38
Related work: ntfs-3g has a separate userspace LZNT1 bounds fix that
checks for two remaining input bytes before reading a sub-block header:
https://github.com/tuxera/ntfs-3g/commit/6aa66d98980ac1d966d7977c7b079f4fe380eb42
This report concerns the in-kernel fs/ntfs implementation and is backed
by a kernel reproducer against the revision above.
Console output:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/console-output.txt
Kernel config:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/kernel-config.txt
PoC:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/poc.c
One-byte image control:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/one-byte-control-console-output.txt
Fixed-kernel control:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/fixed-kernel-console-output.txt
Image builder:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/build_image.py
Initramfs builder:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/build_initramfs.sh
QEMU runner:
https://gist.githubusercontent.com/shaos26/acbe634bf90826a626ed95d0f32b5ab4/raw/ada97c11fe984e4bf47b9c93a0d90d30766ca3c4/run_qemu.sh
Build the test kernel from the specified commit and config. Required
tools are gcc, make, cpio, gzip, QEMU, and the ntfs-3g tools mkntfs and
ntfscp. Run these commands to download the Gist files and build the
kernel, create the images, and run the positive and control cases:
work=$(mktemp -d /tmp/ntfs-lznt.XXXXXX)
cd "$work"
gist_id=acbe634bf90826a626ed95d0f32b5ab4
gist_revision=ada97c11fe984e4bf47b9c93a0d90d30766ca3c4
gist_base=https://gist.githubusercontent.com/shaos26
gist=$gist_base/$gist_id/raw/$gist_revision
for file in poc.c build_image.py build_initramfs.sh run_qemu.sh; do
curl -fL "$gist/$file" -o "$file"
done
git clone \
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux
git checkout 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
mkdir build
curl -fL "$gist/kernel-config.txt" -o build/.config
make O=build olddefconfig
make O=build -j"$(nproc)" bzImage
cd ..
python3 build_image.py images
./build_initramfs.sh poc-init initramfs.cpio.gz
./run_qemu.sh linux/build/arch/x86/boot/bzImage \
initramfs.cpio.gz images/positive.img positive.log
./run_qemu.sh linux/build/arch/x86/boot/bzImage \
initramfs.cpio.gz images/control.img control.log
The image builder creates a positive image and a one-byte control. The
initramfs builder compiles poc.c statically. The PoC mounts
the positive read-only NTFS image as /dev/vda and seeds the shared
buffer by reading offset 0, then reads offset 65536 to trigger the
fault.
The positive image faults in ntfs_decompress() at the end of the 64 KiB
vmalloc buffer. In the preserved run, CR2 is the first byte after the
allocation and RDX is CR2 - 1; the faulting instruction loads a 16-bit
value from RDX. The one-byte image control completes without a fault.
The proposed patch was built and tested against the same positive image;
the fixed kernel completes and returns byte 'A'.
The trigger requires mounting a crafted legacy NTFS volume and reading a
compressed file. It can crash the kernel on the tested x86-64 layout.
This is a local denial of service; no information disclosure or code
execution is demonstrated.
The range check uses the remaining length rather than forming a pointer
beyond cb_end. The Gist includes the positive, one-byte control, and
fixed-kernel console logs.
Fixes: 1e9ea7e04472 ("Revert \"fs: Remove NTFS classic\"")
Signed-off-by: shaos <shawnq1@xxxxxxx>
---
fs/ntfs/compress.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -201,10 +201,11 @@ do_next_sb:
/*
* 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.
+ * position in the compression block is fewer than two bytes before its
+ * end, so a complete sub-block header is no longer available.
*/
- if (cb == cb_end || !le16_to_cpup((__le16 *)cb) ||
+ if (cb_end - cb < sizeof(__le16) ||
+ !le16_to_cpup((__le16 *)cb) ||
(*dest_index == dest_max_index &&
*dest_ofs == dest_max_ofs)) {
int i;
--
2.43.0