pe: check live page protection in pe_map_export #166

Merged
raulmoracode merged 1 commit from upstream-pr/167 into main 2026-11-21 18:08:55 +00:00
raulmoracode commented 2026-11-21 17:51:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by raulmoracode on 2026-11-21T17:51:02Z.


Change

pe_map_export read the export directory, the address table, the name table and the ordinal table after a bounds check against SizeOfImage only. A mapped section can lack read access, by its characteristics or after a run-time reprotect, so the lookup could dereference an unreadable page.

This applies the live protection check that readable() already performs for the TLS directory and callback list:

  • the export directory and the three tables must be readable;
  • each name string is scanned only across readable committed pages;
  • the returned target must be accessible, but may be execute-only, so a code export still resolves.

docs/experiments.md no longer records the check as missing.

Fixes #163

Verification

Commit e5b2605 on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^cpu_native_map$' -V

Result:

cpu_register_probe.dll: export lookup returns null when the export section has no read access
1/1 Test #61: cpu_native_map ...................   Passed    0.50 sec
100% tests passed out of 1

The full CPU group also passes: ctest --preset dev --no-tests=error -R '^cpu_' reported 16/16, including cpu_native_seh, cpu_native_section and cpu_native_tls.

Negative control: with tools/pe_map.cpp reverted to the parent commit and pe_map rebuilt, the same test fails:

Traceback (most recent call last):
OSError: exception: access violation reading 0x000001E074CE21D8
0% tests passed, 1 tests failed out of 1

Evidence and follow-up

The new check is check_unreadable_export in tests/cpu/native_map_check.py. It uses the source-built cpu_register_probe.dll, finds the section that contains the export directory, and rewrites that section's Characteristics on a temporary copy: once without IMAGE_SCN_MEM_READ, and once with IMAGE_SCN_MEM_EXECUTE only. Both copies must resolve no export. The unmodified image is still covered by check_empty_export_slot, so the control that a valid export resolves is unchanged.

pe_map_release accepting a pointer that pe_map_image did not return is a separate question, opened as #164 so it does not widen this change.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532357607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/167). Originally posted by [raulmoracode](https://github.com/raulmoracode) on 2026-11-21T17:51:02Z. --- ## Change `pe_map_export` read the export directory, the address table, the name table and the ordinal table after a bounds check against `SizeOfImage` only. A mapped section can lack read access, by its characteristics or after a run-time reprotect, so the lookup could dereference an unreadable page. This applies the live protection check that `readable()` already performs for the TLS directory and callback list: - the export directory and the three tables must be readable; - each name string is scanned only across readable committed pages; - the returned target must be accessible, but may be execute-only, so a code export still resolves. `docs/experiments.md` no longer records the check as missing. Fixes #163 ## Verification Commit `e5b2605` on Windows 10 22H2 build 19045.6466, VS Build Tools 2022 17.14, MSVC 14.44.35207, Windows SDK 10.0.26100, CMake 4.4.4, Python 3.12.10. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^cpu_native_map$' -V ``` Result: ```text cpu_register_probe.dll: export lookup returns null when the export section has no read access 1/1 Test #61: cpu_native_map ................... Passed 0.50 sec 100% tests passed out of 1 ``` The full CPU group also passes: `ctest --preset dev --no-tests=error -R '^cpu_'` reported 16/16, including `cpu_native_seh`, `cpu_native_section` and `cpu_native_tls`. Negative control: with `tools/pe_map.cpp` reverted to the parent commit and `pe_map` rebuilt, the same test fails: ```text Traceback (most recent call last): OSError: exception: access violation reading 0x000001E074CE21D8 0% tests passed, 1 tests failed out of 1 ``` ## Evidence and follow-up The new check is `check_unreadable_export` in `tests/cpu/native_map_check.py`. It uses the source-built `cpu_register_probe.dll`, finds the section that contains the export directory, and rewrites that section's `Characteristics` on a temporary copy: once without `IMAGE_SCN_MEM_READ`, and once with `IMAGE_SCN_MEM_EXECUTE` only. Both copies must resolve no export. The unmodified image is still covered by `check_empty_export_slot`, so the control that a valid export resolves is unchanged. `pe_map_release` accepting a pointer that `pe_map_image` did not return is a separate question, opened as #164 so it does not widen this change. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:41:38 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!166
No description provided.