Exploit database

GH-945bd5267b0d1b94c3f74faf5cda7e5a

blkph0x/cve-2026-83844_poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-83844

5 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files579
blkph0x/cve-2026-83844_pocRevision 193ed44859da
Next files →

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

lab/trace/inspect_fill_loop_census.py

Python · 14,423 bytes
#!/usr/bin/env python3
"""Inspect a private Fill read census without publishing process addresses.

This checks each captured read at the 13 pinned instructions against the
visited-map allocation request and the declared BitmapData row rectangle.
When the matching heap lookups are present, it additionally checks reported
LFH map and Scan0 backend heap user spans. It does not prove that the signed
instruction inventory is exhaustive.
"""

from __future__ import annotations

import argparse
import json
import re
from collections import Counter
from dataclasses import asdict, dataclass
from pathlib import Path

from build_fill_bounds_profile import READS, ROOT


# CDB can concatenate successive .printf calls onto one physical log line.
# Match completed value tokens anywhere in the transcript; the breakpoint
# definitions contain format placeholders (%p/%u/%x), so they cannot match.
TOKEN_START = r"(?<![A-Za-z0-9_])"
TOKEN_END = r"(?![A-Za-z0-9_])"
READ = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_READ=([a-z_]+):([0-9a-fA-F`x]+):([0-9]+)" + TOKEN_END)
BITMAP = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_BITMAP=([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F]+):([0-9a-fA-F`x]+)" + TOKEN_END)
REQUEST = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_MAP_REQUEST=([0-9]+)" + TOKEN_END)
BASE = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_MAP_BASE=([0-9a-fA-F`x]+)" + TOKEN_END)
TOTAL = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_END_TOTAL=([0-9]+)" + TOKEN_END)
VIOLATIONS = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_MAP_VIOLATIONS=([0-9]+)" + TOKEN_END)
FIRST_VIOLATION = re.compile(TOKEN_START + r"PAINT_FILL_LOOP_FIRST_MAP_VIOLATION=([0-9a-fA-F`x]+):([0-9]+)" + TOKEN_END)
PATTERNS = {
    "read": READ, "bitmap": BITMAP, "request": REQUEST,
    "base": BASE, "total": TOTAL, "violations": VIOLATIONS,
    "first_violation": FIRST_VIOLATION,
}
LOCK_HIT = re.compile(r"(?m)^PAINT_TRACE_HIT=fill_deep_lock_success\s*$")
MAP_RETURN_HIT = re.compile(r"(?m)^PAINT_TRACE_HIT=fill_bounds_map_alloc_return\s*$")
NEXT_HIT = re.compile(r"(?m)^PAINT_TRACE_HIT=")


def backend_pixel_extent(log: str, bitmap: tuple[int, int, int, int]) -> tuple[int, int] | None:
    """Return the measured Scan0 backing user span, if the lock block has it.

    Synthetic/offline marker-only tests have no heap lookup and return None.
    A present but ambiguous heap lookup fails instead of silently falling
    back to the declared LockBits rectangle.
    """
    hits = list(LOCK_HIT.finditer(log))
    if not hits:
        return None
    if len(hits) != 1:
        raise ValueError("Lock-success marker repeated")
    end = NEXT_HIT.search(log, hits[0].end())
    block = log[hits[0].end():end.start() if end else len(log)]

    def one_heap(pattern: str, name: str) -> str:
        values = re.findall(pattern, block, flags=re.MULTILINE | re.IGNORECASE)
        if len(values) != 1:
            raise ValueError(f"Expected one {name} in LockBits heap lookup")
        return values[0]

    status = one_heap(r"^Allocation status\s*:\s*(.+?)\s*$", "heap status")
    header = pointer(one_heap(r"^Chunk header address\s*:\s*([0-9a-f`]+)\s*$",
                              "backend chunk header"))
    chunk_size = int(one_heap(r"^Chunk size \(bytes\)\s*:\s*(\d+)\s*$",
                              "backend chunk size"))
    unused = int(one_heap(r"^Chunk unused bytes\s*:\s*(\d+)\s*$",
                          "backend unused bytes"))
    user_start = header + 16
    user_size = chunk_size - 16 - unused
    if (status != "Variable size allocated chunk." or user_size <= 0 or
            bitmap[3] != user_start):
        raise ValueError("BitmapData.Scan0 is not the measured backend heap user start")
    return user_start, user_start + user_size


def lfh_map_extent(log: str, map_base: int, requested: int) -> tuple[int, int] | None:
    """Return the map's measured LFH user span when the return lookup exists."""
    hits = list(MAP_RETURN_HIT.finditer(log))
    if not hits:
        return None
    if len(hits) != 1:
        raise ValueError("Map allocation-return marker repeated")
    end = NEXT_HIT.search(log, hits[0].end())
    block = log[hits[0].end():end.start() if end else len(log)]

    def one_heap(pattern: str, name: str) -> str:
        values = re.findall(pattern, block, flags=re.MULTILINE | re.IGNORECASE)
        if len(values) != 1:
            raise ValueError(f"Expected one {name} in map heap lookup")
        return values[0]

    status = one_heap(r"^Allocation status\s*:\s*(.+?)\s*$", "map allocation status")
    user_size = int(one_heap(r"^User requested size\s*:\s*(\d+) Bytes\s*$",
                             "map user requested size"))
    unused = int(one_heap(r"^Unused bytes\s*:\s*(\d+)\s*$", "map unused bytes"))
    block_size = int(one_heap(r"^Block Size\s*:\s*(\d+) Bytes\s*$",
                              "map block size"))
    start = pointer(one_heap(r"^Block Address\s*:\s*0x([0-9a-f`]+)\s*$",
                             "map block address"))
    if (status != "LFH Allocated" or start != map_base or
            user_size != requested or user_size <= 0 or
            block_size != user_size + unused):
        raise ValueError("Map return does not match its measured LFH user allocation")
    return start, start + user_size


@dataclass(frozen=True)
class Event:
    site: str
    address: int
    width: int
    offset: int


def pointer(text: str) -> int:
    return int(text.replace("`", "").removeprefix("0x"), 16)


def one(matches: list[tuple[int, object]], label: str):
    if len(matches) != 1:
        raise ValueError(f"Expected one {label}, observed {len(matches)}")
    return matches[0]


def inside_declared_row(address: int, width: int, bitmap: tuple[int, int, int, int]) -> bool:
    image_width, image_height, stride, scan0 = bitmap
    if image_width <= 0 or image_height <= 0 or stride == 0:
        return False
    for row in range(image_height):
        start = scan0 + row * stride
        if start <= address and address + width <= start + image_width * 4:
            return (address - start) % 4 == 0
    return False


def inspect(log: str, build: str) -> dict[str, object]:
    if build not in READS:
        raise ValueError("Unknown signed build")
    known = {site.label: site for site in READS[build]}
    events: list[Event] = []
    fields: dict[str, list[tuple[int, object]]] = {
        "bitmap": [], "request": [], "base": [], "total": [],
        "violations": [], "first_violation": [],
    }
    tokens = sorted(
        (match.start(), kind, match)
        for kind, pattern in PATTERNS.items()
        for match in pattern.finditer(log)
    )
    for offset, kind, match in tokens:
        if kind == "read":
            label, address, width = match.groups()
            site = known.get(label)
            if site is None or int(width) != site.width:
                raise ValueError(f"Unpinned read site or width at offset {offset}")
            events.append(Event(label, pointer(address), int(width), offset))
        elif kind == "bitmap":
            width, height, stride, scan0 = match.groups()
            signed_stride = int(stride, 16)
            if signed_stride >= 1 << 31:
                signed_stride -= 1 << 32
            fields["bitmap"].append((offset, (int(width, 16), int(height, 16),
                                                    signed_stride, pointer(scan0))))
        elif kind == "request":
            fields["request"].append((offset, int(match.group(1))))
        elif kind == "base":
            fields["base"].append((offset, pointer(match.group(1))))
        elif kind == "total":
            fields["total"].append((offset, int(match.group(1))))
        elif kind == "violations":
            fields["violations"].append((offset, int(match.group(1))))
        elif kind == "first_violation":
            fields["first_violation"].append((offset,
                                               (pointer(match.group(1)), int(match.group(2)))))

    bitmap_offset, bitmap = one(fields["bitmap"], "BitmapData record")
    request_offset, request_size = one(fields["request"], "map request")
    base_offset, map_base = one(fields["base"], "map return")
    end_offset, total = one(fields["total"], "Execute-end total")
    _, debugger_violations = one(fields["violations"], "debugger violation count")
    if not (bitmap_offset < request_offset < base_offset < end_offset):
        raise ValueError("Allocation and Execute marker order mismatch")
    if not events or len(events) != total:
        raise ValueError(f"Read event count {len(events)} differs from Execute total {total}")
    if any(event.offset <= bitmap_offset or event.offset >= end_offset for event in events):
        raise ValueError("A read event lies outside the measured Fill operation")
    if request_size <= 0 or map_base == 0:
        raise ValueError("Map allocation request or return was not usable")

    out_of_map: list[Event] = []
    map_events: list[Event] = []
    out_of_declared_pixel: list[Event] = []
    pixel_events: list[Event] = []
    for event in events:
        site = known[event.site]
        if site.kind == "visited_map":
            map_events.append(event)
            if event.offset <= base_offset:
                raise ValueError("A visited-map read preceded the recorded allocation return")
            if not (map_base <= event.address and
                    event.address + event.width <= map_base + request_size):
                out_of_map.append(event)
        else:
            pixel_events.append(event)
            if not inside_declared_row(event.address, event.width, bitmap):
                out_of_declared_pixel.append(event)
    if debugger_violations != len(out_of_map):
        raise ValueError("Debugger map-violation counter differs from offline event check")
    if bool(fields["first_violation"]) != bool(out_of_map):
        raise ValueError("First map-violation marker differs from offline event check")
    if out_of_map and fields["first_violation"][0][1] != (
            out_of_map[0].address, out_of_map[0].width):
        raise ValueError("First map-violation marker names a different event")

    backing = backend_pixel_extent(log, bitmap)
    map_backing = lfh_map_extent(log, map_base, request_size)
    out_of_map_backing: list[Event] = []
    if map_backing is not None:
        start, end = map_backing
        out_of_map_backing = [event for event in map_events
                              if not (start <= event.address and
                                      event.address + event.width <= end)]
    outside_backing: list[Event] = []
    if backing is not None:
        start, end = backing
        outside_backing = [event for event in pixel_events
                           if not (start <= event.address and
                                   event.address + event.width <= end)]

    def pixel_margin(event: Event) -> dict[str, int]:
        assert backing is not None
        start, end = backing
        return {"offset_from_user_start_bytes": event.address - start,
                "bytes_from_read_end_to_user_end": end - (event.address + event.width)}

    counts = Counter(event.site for event in events)
    return {
        "schema": "paint-fill-loop-census-private-review-v1",
        "build": build,
        "read_event_count": len(events),
        "execute_total_matches": True,
        "read_site_counts": {site.label: counts[site.label] for site in READS[build]},
        "bitmap_width": bitmap[0],
        "bitmap_height": bitmap[1],
        "bitmap_stride": bitmap[2],
        "map_request_bytes": request_size,
        "map_reads_outside_requested_span": len(out_of_map),
        "map_lfh_heap_user_bytes": (
            map_backing[1] - map_backing[0] if map_backing is not None else None),
        "map_return_is_lfh_heap_user_start": map_backing is not None,
        "map_reads_outside_reported_heap_user_span": (
            len(out_of_map_backing) if map_backing is not None else None),
        "pixel_reads_outside_declared_rows": len(out_of_declared_pixel),
        "pixel_backend_heap_user_bytes": (
            backing[1] - backing[0] if backing is not None else None),
        "pixel_scan0_is_backend_heap_user_start": backing is not None,
        "pixel_reads_outside_reported_heap_user_span": (
            len(outside_backing) if backing is not None else None),
        "first_pixel_read_heap_margin": (
            pixel_margin(pixel_events[0]) if backing and pixel_events else None),
        "last_pixel_read_heap_margin": (
            pixel_margin(pixel_events[-1]) if backing and pixel_events else None),
        "minimum_pixel_bytes_from_read_end_to_heap_user_end": (
            min(pixel_margin(event)["bytes_from_read_end_to_user_end"]
                for event in pixel_events) if backing and pixel_events else None),
        "first_map_violation": asdict(out_of_map[0]) if out_of_map else None,
        "first_declared_pixel_violation": (
            asdict(out_of_declared_pixel[0]) if out_of_declared_pixel else None
        ),
        "claim_limit": (
            "The 13 pinned read sites were checked for every logged hit through "
            "Execute. When the map and LockBits heap lookups are present, each "
            "read is also checked against its reported heap user extent. "
            "CFG-complete access coverage and all-read memory safety "
            "are not established. Raw addresses in this private review must "
            "not be published."
        ),
    }


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--build", choices=("old", "new"), required=True)
    parser.add_argument("--log", type=Path, required=True)
    parser.add_argument("--out", type=Path, required=True)
    args = parser.parse_args()
    output = args.out.resolve()
    private_roots = (ROOT / "lab/output", ROOT / "lab/results")
    if not any(output.is_relative_to(path.resolve()) for path in private_roots):
        raise ValueError("Private review output must stay under ignored lab output")
    result = inspect(args.log.read_text(encoding="utf-8", errors="replace"), args.build)
    output.parent.mkdir(parents=True, exist_ok=True)
    output.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
    print(f"Reviewed {result['read_event_count']} private Fill read events; {output}")


if __name__ == "__main__":
    main()