linux/fs/ntfs3
Michael Bommarito 8e4ba5a38c ntfs3: validate split-point offset in indx_insert_into_buffer
[ Upstream commit f1df9d771d ]

indx_insert_into_buffer() computes

    used = used1 - to_copy - sp_size;
    memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));

where sp and sp_size come from hdr_find_split().  hdr_find_split()
walks entries by le16_to_cpu(e->size) without validating that each
step stays within hdr->used or that the size field is at least
sizeof(struct NTFS_DE).  index_hdr_check(), the on-load gatekeeper,
only validates header-level fields (used, total, de_off) and does
not walk per-entry sizes.

A crafted NTFS image whose leaf INDEX_HDR reports used == total but
contains one interior NTFS_DE with size = 0xFFF0 therefore passes
validation, descends to indx_insert_into_buffer() through the
ntfs_create() -> indx_insert_entry() path, and makes hdr_find_split()
return an sp whose sp_size (0xFFF0) greatly exceeds the remaining
bytes in the buffer.  The u32 subtraction underflows and the memmove
count becomes a near-4-GiB value, producing an out-of-bounds kernel
write that corrupts adjacent allocations and panics the kernel.

Reproduced on 7.0.0-rc7 with UML + KASAN via a crafted image and a
single 'touch' inside the mounted directory; crash site resolves to
fs/ntfs3/index.c at the memmove.  Trigger requires only local mount
of an attacker-supplied filesystem image (USB, loopback, or removable
media auto-mount).

Reject the split whenever the chosen sp plus its declared size
already extends past hdr1->used.  This is the minimal fix; it
preserves the existing hdr_find_split() contract and relies on the
same out: cleanup path as the pre-existing error returns.

A prior OOB read in the very same indx_insert_into_buffer() memmove
was fixed in commit b8c4494904 ("fs/ntfs3: Fix OOB read in
indx_insert_into_buffer") by tightening hdr_find_e(), but that fix
does not cover the split-point size field path addressed here: sp is
returned by hdr_find_split(), not hdr_find_e(), and the underflow is
driven by sp->size rather than hdr->used exceeding hdr->total.

Fixes: 82cae269cf ("fs/ntfs3: Add initialization of super block")
Cc: stable@vger.kernel.org
Reported-by: Michael Bommarito <michael.bommarito@gmail.com>
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-08-23 14:17:21 +02:00
..
lib fs/ntfs3: Add missing header and guards to lib/ headers 2021-09-13 19:41:44 +03:00
attrib.c fs: ntfs3: fix infinite loop in attr_load_runs_range on inconsistent metadata 2026-03-04 07:20:18 -05:00
attrlist.c fs: ntfs3: fix infinite loop triggered by zero-sized ATTR_LIST 2026-03-04 07:20:18 -05:00
bitfunc.c fs/ntfs3: Remove a useless shadowing variable 2021-09-23 19:05:46 +03:00
bitmap.c fs/ntfs3: Fix a resource leak bug in wnd_extend() 2025-10-19 16:21:45 +02:00
debug.h fs/ntfs3. Add forward declarations for structs to debug.h 2021-09-13 19:41:43 +03:00
dir.c fs/ntfs3: Add sanity check for file name 2025-08-28 16:24:17 +02:00
file.c fs/ntfs3: prevent infinite loops caused by the next valid being the same 2026-03-04 07:19:49 -05:00
frecord.c fs/ntfs3: Prevent memory leaks in add sub record 2026-01-19 13:09:31 +01:00
fslog.c ntfs3: cap RESTART_TABLE free-chain walker at rt->used 2026-07-24 15:51:49 +02:00
fsntfs.c fs/ntfs3: Make ntfs_update_mftmirr return void 2026-08-23 14:17:21 +02:00
index.c ntfs3: validate split-point offset in indx_insert_into_buffer 2026-08-23 14:17:21 +02:00
inode.c fs/ntfs3: Initialize allocated memory before use 2026-02-06 16:42:03 +01:00
Kconfig fs/ntfs3: Add Kconfig, Makefile and doc 2021-08-13 07:56:37 -07:00
lznt.c ntfs3: fix out-of-bounds read in decompress_lznt 2026-07-24 15:51:49 +02:00
Makefile fs/ntfs3: Add Kconfig, Makefile and doc 2021-08-13 07:56:37 -07:00
namei.c fs/ntfs3: fix syncing wrong inode on DIRSYNC cross-directory rename 2026-07-24 15:51:49 +02:00
ntfs.h fs/ntfs3: Fix field-spanning write in INDEX_HDR 2024-08-19 05:45:09 +02:00
ntfs_fs.h fs/ntfs3: Make ntfs_update_mftmirr return void 2026-08-23 14:17:21 +02:00
record.c fs/ntfs3: Add more attributes checks in mi_enum_attr() 2026-06-01 17:35:11 +02:00
run.c ntfs3: fix integer overflow in run_unpack() volume boundary check 2026-06-01 17:35:18 +02:00
super.c fs/ntfs3: terminate the cached volume label after UTF-8 conversion 2026-06-01 17:35:36 +02:00
upcase.c fs/ntfs3: Change right headers to upcase.c 2021-09-13 19:41:45 +03:00
xattr.c ntfs3: reject direct userspace writes to reserved $LX* xattrs 2026-07-04 13:39:39 +02:00