pe_map_export reads export tables without checking page protection #163

Closed
opened 2026-11-26 21:31:29 +00:00 by github-bot · 0 comments
Owner

@⁠raulmoracode on GitHub · 2026-11-21 17:50 UTC · original

Affected file

tools/pe_map.cpp, pe_map_export

Description

pe_map_export bounds-checks the export directory, the address table, the name table and the ordinal table against SizeOfImage, but it never checks the live page protection before reading them. Image bounds alone do not make bytes readable: a mapped section can lack read access, either by its characteristics or after a run-time reprotect.

readable() already exists in the same file and is used for the TLS directory and the TLS callback list. The export lookup does not use it. docs/experiments.md records the gap: "pe_map_export does not yet apply this check to the export tables."

Expected behavior

A lookup against a copy whose export section is mapped without read access returns nullptr. A valid copy resolves the same export as before. An export target on an execute-only page is still returned, because that address can be called.

Observed behavior

With the export section mapped PAGE_NOACCESS, pe_map_export dereferences the export directory and the host process terminates:

Traceback (most recent call last):
OSError: exception: access violation reading 0x000001E074CE21D8

Reproduction

  1. Build with the dev preset.
  2. Copy cpu_register_probe.dll and clear IMAGE_SCN_MEM_READ (0x40000000) in the section that contains the export directory. A second copy sets IMAGE_SCN_MEM_EXECUTE instead, which maps the section PAGE_EXECUTE.
  3. Map the copy with pe_map_image and call pe_map_export(base, b"probe").

The exact Python steps are the check_unreadable_export check proposed in the linked pull request. On current main the call crashes; with that check added, both copies return nullptr and the existing exports still resolve.

Impact

A malformed or deliberately reprotected image can crash the host instead of failing the lookup, inside the path that resolves exports from mapped images.

Environment

Windows 10 22H2 build 19045, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10, commit c1a65f0. No GPU is used by this check.

AI-assisted.

**@⁠raulmoracode** on GitHub · 2026-11-21 17:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/163) ## Affected file `tools/pe_map.cpp`, `pe_map_export` ## Description `pe_map_export` bounds-checks the export directory, the address table, the name table and the ordinal table against `SizeOfImage`, but it never checks the live page protection before reading them. Image bounds alone do not make bytes readable: a mapped section can lack read access, either by its characteristics or after a run-time reprotect. `readable()` already exists in the same file and is used for the TLS directory and the TLS callback list. The export lookup does not use it. `docs/experiments.md` records the gap: "`pe_map_export` does not yet apply this check to the export tables." ## Expected behavior A lookup against a copy whose export section is mapped without read access returns `nullptr`. A valid copy resolves the same export as before. An export target on an execute-only page is still returned, because that address can be called. ## Observed behavior With the export section mapped `PAGE_NOACCESS`, `pe_map_export` dereferences the export directory and the host process terminates: ```text Traceback (most recent call last): OSError: exception: access violation reading 0x000001E074CE21D8 ``` ## Reproduction 1. Build with the dev preset. 2. Copy `cpu_register_probe.dll` and clear `IMAGE_SCN_MEM_READ` (`0x40000000`) in the section that contains the export directory. A second copy sets `IMAGE_SCN_MEM_EXECUTE` instead, which maps the section `PAGE_EXECUTE`. 3. Map the copy with `pe_map_image` and call `pe_map_export(base, b"probe")`. The exact Python steps are the `check_unreadable_export` check proposed in the linked pull request. On current `main` the call crashes; with that check added, both copies return `nullptr` and the existing exports still resolve. ## Impact A malformed or deliberately reprotected image can crash the host instead of failing the lookup, inside the path that resolves exports from mapped images. ## Environment Windows 10 22H2 build 19045, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10, commit `c1a65f0`. No GPU is used by this check. _AI-assisted._
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:31:29 +00:00
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#163
No description provided.