ntfs3: fix OOB write in attr_wof_frame_info()
PATCH 1/1 ntfs3: fix OOB write in attr_wof_frame_info()
In attr_wof_frame_info(), the offset-table read range for a nonresident WofCompressedData stream is:
u64 from = vbo[i] & ~(u64)(PAGE_SIZE - 1);
u64 to = min(from + PAGE_SIZE, wof_size);
...
ntfs_read_run(sbi, run, addr, from, to - from);A crafted image sets WofCompressedData.nres.data_size to 0xfff while the file is large enough to request frame 1024 (offset 0x400000). This gives from=0x1000, to=0xfff. The unsigned (to - from) wraps to 0xffffffffffffffff and ntfs_read_write_run() overflows the single-page offs_folio via memcpy.
Triggered by pread() on a mounted NTFS image. Depending on adjacent memory layout at the time of the overflow, KASAN reports this as slab-out-of-bounds, use-after-free, or slab-use-after-free all at ntfs_read_write_run(). Secondary corruption/panic paths were also observed.
Reject the read when the offset-table page is outside the stream.
---
Reproducer:
Create the crafted NTFS image:
python3 create_wof_poc.py -o wof-poc.img
Mount it read-only with ntfs3:
sudo mount -t ntfs3 -o loop,ro wof-poc.img /mnt
Build the trigger:
cc -O2 -static wof_offset_table_read_trigger.c -o trigger
Trigger the bug:
./trigger /mnt/poc.bin 0x400000 1
KASAN report on 6.19.10:
==================================================================
BUG: KASAN: slab-out-of-bounds in ntfs_read_write_run+0x321/0x450 [ntfs3] Write of size 4096 at addr ffff88800353b000 by task trigger-static/55 Call Trace: __asan_memcpy+0x3c/0x60 ntfs_read_write_run+0x321/0x450 [ntfs3] attr_wof_frame_info+0x52b/0xbc0 [ntfs3] ni_read_frame+0x3cc/0xfe0 [ntfs3] ni_read_folio_cmpr+0x3b9/0x820 [ntfs3] read_pages+0x58a/0x810 page_cache_ra_unbounded+0x29c/0x5d0 filemap_get_pages+0x2c8/0x1530 filemap_read+0x2e7/0xb80 vfs_read+0x6da/0xa40 __x64_sys_pread64+0x195/0x250 ==================================================================
fs/ntfs3/attrib.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ntfs3/attrib.c +6 -0
@@ -1576,6 +1576,12 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,u64 from = vbo[i] & ~(u64)(PAGE_SIZE -1 );u64 to =min (from +PAGE_SIZE , wof_size); +if (from >= wof_size) { +_ntfs_bad_inode (&ni->vfs_inode); + err = -EINVAL ; + goto out1; + } + err =attr_load_runs_range (ni,ATTR_DATA ,WOF_NAME ,ARRAY_SIZE (WOF_NAME ), run, from, to);
Signature · 1 line
2.50.1 (Apple Git-155)
Attaching the PoC image generator and trigger program referenced in the reproducer.
Quoted 77 lines · On Sun, 29 Mar 2026 at 13:58, 0xkato <[email protected]> wrote:
In
attr_wof_frame_info(), the offset-table read range for a nonresident WofCompressedData stream is:u64 from = vbo[i] & ~(u64)(PAGE_SIZE - 1); u64 to = min(from + PAGE_SIZE, wof_size); ... ntfs_read_run(sbi, run, addr, from, to - from);A crafted image sets WofCompressedData.nres.data_size to
0xfffwhile the file is large enough to request frame 1024 (offset0x400000). This gives from=0x1000, to=0xfff. The unsigned (to - from) wraps to0xffffffffffffffffandntfs_read_write_run()overflows the single-pageoffs_foliovia memcpy.Triggered by
pread()on a mounted NTFS image. Depending on adjacent memory layout at the time of the overflow, KASAN reports this as slab-out-of-bounds, use-after-free, or slab-use-after-free all atntfs_read_write_run(). Secondary corruption/panic paths were also observed.Reject the read when the offset-table page is outside the stream.
Signed-off-by 0xkato <[email protected]>---
Reproducer:Create the crafted NTFS image:
python3create_wof_poc.py-o wof-poc.imgMount it read-only with ntfs3:
sudo mount -t ntfs3 -o loop,ro wof-poc.img /mntBuild the trigger:
cc -O2 -staticwof_offset_table_read_trigger.c-o triggerTrigger the bug:
./trigger /mnt/poc.bin 0x400000 1KASAN report on 6.19.10:
==================================================================
BUG: KASAN: slab-out-of-bounds in ntfs_read_write_run+0x321/0x450 [ntfs3] Write of size 4096 at addr ffff88800353b000 by task trigger-static/55 Call Trace: __asan_memcpy+0x3c/0x60 ntfs_read_write_run+0x321/0x450 [ntfs3] attr_wof_frame_info+0x52b/0xbc0 [ntfs3] ni_read_frame+0x3cc/0xfe0 [ntfs3] ni_read_folio_cmpr+0x3b9/0x820 [ntfs3] read_pages+0x58a/0x810 page_cache_ra_unbounded+0x29c/0x5d0 filemap_get_pages+0x2c8/0x1530 filemap_read+0x2e7/0xb80 vfs_read+0x6da/0xa40 __x64_sys_pread64+0x195/0x250 ==================================================================fs/ntfs3/attrib.c | 6 ++++++ 1 file changed, 6 insertions(+)fs/ntfs3/attrib.c +6
-0@@ -1576,6 +1576,12 @@ int attr_wof_frame_info(struct ntfs_inode *ni,struct ATTRIB *attr, u64 from = vbo[i] & ~(u64)(PAGE_SIZE - 1);u64 to =min (from +PAGE_SIZE , wof_size); +if (from >= wof_size) { +_ntfs_bad_inode (&ni->vfs_inode); + err = -EINVAL ; + goto out1; + } + err = attr_load_runs_range(ni, ATTR_DATA, WOF_NAME, ARRAY_SIZE(WOF_NAME),run,
Quoted 5 lines
from, to);--
2.50.1 (Apple Git-155)
#!/usr/bin/env python3
"""
Restore the preserved ntfs3 WOF offset-table PoC image from the minimal archive.
The original PoC generator was lost from /tmp, but the known-good lab image and manifest still exist inside /home/kato/Downloads/ntfs3-wof-poc-minimal.tar.gz. This script reconstructs the report attachment interface:
python3 create_wof_poc.py -o wof-poc.img
Optionally emit the preserved manifest as well:
python3 create_wof_poc.py -o wof-poc.img --manifest wof-poc.env
"""
from __future__ import annotations
import argparse
import hashlib
import shutil
import sys
import tarfile
from pathlib import Path
ARCHIVE_NAME = "ntfs3-wof-poc-minimal.tar.gz"IMAGE_MEMBER = "tools/research/ntfs3/lab/wof-poc.img" MANIFEST_MEMBER = "tools/research/ntfs3/lab/wof-poc.env" DEFAULT_ARCHIVE = Path(__file__).resolve().parent.parent / ARCHIVE_NAME
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Recreate the ntfs3 WOF offset-table PoC image from the saved archive.",
)
parser.add_argument(
"-o",
"--output",
required=True,
type=Path,
help="Path to write the PoC image to.",
)
parser.add_argument(
"--manifest",
type=Path,
help="Optional path to also write the preserved manifest to.",
)
parser.add_argument(
"--archive",
type=Path,
default=DEFAULT_ARCHIVE,
help=f"Archive containing the saved PoC assets (default: {DEFAULT_ARCHIVE}).",
)
parser.add_argument(
"-f",
"--force",
action="store_true",
help="Overwrite existing output files.",
)
return parser.parse_args()def ensure_writable(path: Path, force: bool) -> None:
if path.exists() and not force:
raise FileExistsError(f"refusing to overwrite existing file: {path}")
path.parent.mkdir(parents=True, exist_ok=True)
def extract_member(tf: tarfile.TarFile, member_name: str, dst: Path, force: bool) -> int:
ensure_writable(dst, force)
member = tf.getmember(member_name)
src = tf.extractfile(member)
if src is None:
raise FileNotFoundError(f"archive member is not a regular file: {member_name}")
with src, open(dst, "wb") as out:
shutil.copyfileobj(src, out)
return member.size
def sha256sum(path: Path) -> str:
digest = hashlib.sha256()
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()def main() -> int:
args = parse_args()
archive = args.archive.resolve()
output = args.output.resolve()
manifest = args.manifest.resolve() if args.manifest else None
if not archive.is_file():
print(f"error: archive not found: {archive}", file=sys.stderr) return 1
try:
with tarfile.open(archive, "r:gz") as tf:
image_size = extract_member(tf, IMAGE_MEMBER, output, args.force) manifest_size = None
if manifest is not None:
manifest_size = extract_member(tf, MANIFEST_MEMBER, manifest, args.force)
except (FileExistsError, FileNotFoundError, KeyError, tarfile.TarError, OSError) as exc:
print(f"error: {exc}", file=sys.stderr)
return 1
print(f"wrote image: {output} ({image_size} bytes)") print(f"sha256: {sha256sum(output)}")
if manifest is not None and manifest_size is not None:
print(f"wrote manifest: {manifest} ({manifest_size} bytes)")
print("target file: /poc.bin")
print("trigger offset: 0x400000")
return 0
if __name__ == "__main__":
raise SystemExit(main())
Konstantin Komarov
maintainerQuoted 79 lines · On 3/29/26 13:57, 0xkato wrote:
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
In
attr_wof_frame_info(), the offset-table read range for a nonresident WofCompressedData stream is:u64 from = vbo[i] & ~(u64)(PAGE_SIZE - 1); u64 to = min(from + PAGE_SIZE, wof_size); ... ntfs_read_run(sbi, run, addr, from, to - from);A crafted image sets WofCompressedData.nres.data_size to
0xfffwhile the file is large enough to request frame 1024 (offset0x400000). This gives from=0x1000, to=0xfff. The unsigned (to - from) wraps to0xffffffffffffffffandntfs_read_write_run()overflows the single-pageoffs_foliovia memcpy.Triggered by
pread()on a mounted NTFS image. Depending on adjacent memory layout at the time of the overflow, KASAN reports this as slab-out-of-bounds, use-after-free, or slab-use-after-free all atntfs_read_write_run(). Secondary corruption/panic paths were also observed.Reject the read when the offset-table page is outside the stream.
Signed-off-by 0xkato <[email protected]>---
Reproducer:Create the crafted NTFS image:
python3create_wof_poc.py-o wof-poc.imgMount it read-only with ntfs3:
sudo mount -t ntfs3 -o loop,ro wof-poc.img /mntBuild the trigger:
cc -O2 -staticwof_offset_table_read_trigger.c-o triggerTrigger the bug:
./trigger /mnt/poc.bin 0x400000 1KASAN report on 6.19.10:
================================================================== BUG: KASAN: slab-out-of-bounds in ntfs_read_write_run+0x321/0x450 [ntfs3] Write of size 4096 at addr ffff88800353b000 by task trigger-static/55 Call Trace: __asan_memcpy+0x3c/0x60 ntfs_read_write_run+0x321/0x450 [ntfs3] attr_wof_frame_info+0x52b/0xbc0 [ntfs3] ni_read_frame+0x3cc/0xfe0 [ntfs3] ni_read_folio_cmpr+0x3b9/0x820 [ntfs3] read_pages+0x58a/0x810 page_cache_ra_unbounded+0x29c/0x5d0 filemap_get_pages+0x2c8/0x1530 filemap_read+0x2e7/0xb80 vfs_read+0x6da/0xa40 __x64_sys_pread64+0x195/0x250 ==================================================================fs/ntfs3/attrib.c | 6 ++++++ 1 file changed, 6 insertions(+)fs/ntfs3/attrib.c +6
-1@@ -1576,6 +1576,12 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,u64 from = vbo[i] & ~(u64)(PAGE_SIZE -1 );u64 to =min (from +PAGE_SIZE , wof_size); +if (from >= wof_size) { +_ntfs_bad_inode (&ni->vfs_inode); + err = -EINVAL ; + goto out1; + } + err =attr_load_runs_range (ni,ATTR_DATA ,WOF_NAME ,ARRAY_SIZE (WOF_NAME ), run, from, to); --
Quoted 2 lines
2.50.1 (Apple Git-155)
Hello,
Your patch is applied. Thank you.
Regards,
Konstantin