mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hyunchul Lee <hyc.lee@gmail.com>
To: shaos <shawnq1@163.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>,
	ntfs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ntfs: guard the final LZNT1 sub-block header read
Date: Wed, 25 Nov 2026 16:39:18 +0900	[thread overview]
Message-ID: <awaQpiz7OUqAOogd@hyunchul-PC02> (raw)
In-Reply-To: <179558384099.146091.12975349907127521352@163.com>

On Wed, Nov 25, 2026 at 05:17:20AM +0000, shaos wrote:
> 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@163.com>
> ---
>  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) ||

Could we go to return_overflow if only one byte remains for the next
header? And the existing phrase-token path seems to need a simillar check.

Could you also format the commit messages with the Linux kernel patch
submission guidelines, and address the warnings reported by
scripts/checkpatch.pl?


> +	    !le16_to_cpup((__le16 *)cb) ||
>  			(*dest_index == dest_max_index &&
>  			*dest_ofs == dest_max_ofs)) {
>  		int i;
> -- 
> 2.43.0
> 
> 

-- 
Thanks,
Hyunchul

  reply	other threads:[~2026-11-25  7:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  5:17 shaos
2026-11-25  7:39 ` Hyunchul Lee [this message]
2026-11-25  8:50 ` [PATCH v2] " shaos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awaQpiz7OUqAOogd@hyunchul-PC02 \
    --to=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs@lists.linux.dev \
    --cc=shawnq1@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®