fix(relinker): enforce page alignment bounds and audit WindowsMappings write-watch #15900

Closed
slopgobblercobbler wants to merge 5 commits from upstream-pr/15900 into main
slopgobblercobbler commented 2026-11-04 22:48:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-04T22:48:11Z.


Depends on: none

What

  • Standardize relinker page size constants (kHostPageSize = 0x1000, kPs5PageSize = 0x4000) and enforce header block alignment in ProgramHeaderLayoutBuilder.cpp.
  • Validate power-of-two alignment for WindowsLoadImage segments in WindowsLoadImage.cpp.
  • Author comprehensive negative boundary test suite RelinkerPageAlignmentAsanTests.cpp covering 16KB/4KB page alignment, address overflow rejection, unsupported permission flags, WindowsLoadImage segment bounds, write-watch boundary alignment safety, and ASAN guard page allocation isolation safety.
  • Audit PS5 16KB page alignment (PAGE_SIZE = 16384) and write-watch boundaries in WindowsWriteWatch.cpp, validating boundary write tracking, MapAlias alignment enforcement, BeginHostWrite/EndHostWrite brackets, and ResidentSpan consistency.
  • Audit MapZero read-only page creation, HandleRead validation, SetProtection transitions across page boundaries, HandleWrite refusal on read-only pages, and TouchedPages multi-page translation from 4KB host subpages to 16KB guest pages.

Tested

  • Tested locally on Windows x64 with MSVC C++20 and Ninja under -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON.
  • 100% CTest pass rate across all relinker test groups: relinker_page_alignment_asan_tests (10/10 cases passed), guest_load_ranges_tests (all cases passed), elf_reader_bounds_tests (all cases passed), program_layout_ranges_tests (29 cases passed), and section_header_ranges_tests (21 cases passed), with 3x repeat verification.
  • Executed direct compilation and run of WindowsWriteWatch.cpp under MSVC C++20 with all test cases passing cleanly in default mode and --verify-direct under APS5_VERIFY_DIRECT_COLLECT=1.
  • Checked project conventions via python tools/check_conventions.py --base upstream/main --head HEAD: 0 findings reported.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5162869853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15900). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-04T22:48:11Z. --- Depends on: none ### What - Standardize relinker page size constants (kHostPageSize = 0x1000, kPs5PageSize = 0x4000) and enforce header block alignment in `ProgramHeaderLayoutBuilder.cpp`. - Validate power-of-two alignment for WindowsLoadImage segments in `WindowsLoadImage.cpp`. - Author comprehensive negative boundary test suite `RelinkerPageAlignmentAsanTests.cpp` covering 16KB/4KB page alignment, address overflow rejection, unsupported permission flags, WindowsLoadImage segment bounds, write-watch boundary alignment safety, and ASAN guard page allocation isolation safety. - Audit PS5 16KB page alignment (PAGE_SIZE = 16384) and write-watch boundaries in `WindowsWriteWatch.cpp`, validating boundary write tracking, MapAlias alignment enforcement, BeginHostWrite/EndHostWrite brackets, and ResidentSpan consistency. - Audit MapZero read-only page creation, HandleRead validation, SetProtection transitions across page boundaries, HandleWrite refusal on read-only pages, and TouchedPages multi-page translation from 4KB host subpages to 16KB guest pages. ### Tested - Tested locally on Windows x64 with MSVC C++20 and Ninja under `-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON`. - 100% CTest pass rate across all relinker test groups: `relinker_page_alignment_asan_tests` (10/10 cases passed), `guest_load_ranges_tests` (all cases passed), `elf_reader_bounds_tests` (all cases passed), `program_layout_ranges_tests` (29 cases passed), and `section_header_ranges_tests` (21 cases passed), with 3x repeat verification. - Executed direct compilation and run of `WindowsWriteWatch.cpp` under MSVC C++20 with all test cases passing cleanly in default mode and `--verify-direct` under `APS5_VERIFY_DIRECT_COLLECT=1`. - Checked project conventions via `python tools/check_conventions.py --base upstream/main --head HEAD`: 0 findings reported. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes

Pull request closed

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
boykopovar/AnyPS5!15900
No description provided.