fix(libc): refuse Windows read traps over host regions in the guest arena #28028
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28028"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:01:48Z.
What
windows_read_trap_unknownfails on Windowsmain(a163d4b886) every run:The Windows
ReadTraps::TrapReadsonly checks that the range falls inside the guest arena's address span (GuestArenaContains_nid_postfix). On Windows that span runs from0x10000toApplicationAreaEnd, and the arena reserves only what was free when it was created. Whatever the host already had mapped there stays a host region (_holes, then_hostRegions). When the host frees one of those regions, a later hostVirtualAlloccan land in it. The test'sVirtualAllocpage landed at0x340000,0xab0000and0xa0000in three runs. A probe in the test gaveGuestArenaContains = 1andGuestArenaHostRegionOverlaps = 1for all three.TrapReadsaccepted that page and set it toPAGE_NOACCESS. The next host read of it would fault into the trap handler, and the resolver would store guest bytes over host memory.TrapReadsnow also refuses a range that overlaps a host region (GuestArenaHostRegionOverlaps_nid_postfix), asOwnedByGuestinGuestArena.cppalready does for guest stores. On Windows the host region list is built once when the arena is created and never changes after that (ReleaseHostRegionis not built on Windows). The lookup is the binary search ofHostRegionIndex, so trapping a guest range costs one search more. Guest ranges never overlap a host region, so their traps are unchanged.The test landed with
650df957b4(2026-11-24), after the last Windows Build run that finished (ab6fe4a981), so CI has not run it yet.Tested
Windows 11, WinLibs GCC 15.2, Release, on
maina163d4b886. I ran the 14windows_read_trap_*andwindows_write_watch*tests withctest -R '^(windows_read_trap_.*|windows_write_watch.*)$' --repeat until-fail:10:main:windows_read_trap_unknownfails on its first run.windows_write_watchfailed once. That is the unrelated flaky case fixed in #28027.I also ran the read trap and write watch GPU tests, 3 runs each on the NVIDIA GeForce RTX 5080 and the AMD Radeon gfx1036 iGPU, with
VK_LAYER_KHRONOS_validationinserted:mainand with this change.VUID-error.The tests covered were
agc_read_traps_over_host_pointer_imports_driver,agc_driver_label_trap_committer_resolve,agc_write_tracking*andagc_write_watch_coverage*.The full CPU suite (5,120 tests), with this change applied to
maina163d4b886in a batch with other reviews, has no failure from this change. The three that failed areframe_capture_minimize(a load timeout that also fails onmain),guest_np_common_runtime(from another PR in the batch) andguest_webrtc_null_socket_server, a load flake that passes 30/30 when rerun.windows_read_trap_unknownpasses in it.The branch is rebased onto
main4c7578e0a4. None of the 30 commits in between touch this file.python3 tools/pr_overlap.py --names TrapReadsreports no matching export changes, becauseTrapReadsis not an export.python3 tools/pr_overlap.py --branch fix/libc-windows-read-trap-host-regionsmerged all 8 open PRs that shareGuestWriteWatch.cppinto the base. It could not compare two of them, because they conflict withmain, so I compared those by hand:WatchandGuestWriteWatchCollect*.Neither touches the Windows
ReadTraps.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T09:21:58Z.
Review: APPROVED
Reviewed — looks good
The host region overlap guard rejects ranges that should not be read-trapped, and the reviewed code supports merging this change.
What I ran
Reviewed head
a6b85c7654c625dd6c994e886aea8c07e98f20b3using the prepared diff andrepo_read.pyfor targeted source reads; no tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported Windows and GPU test results were not independently verified.
GuestWriteWatch.cppwas read aroundTrapReadsand the changed guard;GuestArena.cppwas read aroundOwnedByGuestand the overlap helper;HostRegionIndex.hppwas read in full. No excluded changed files were listed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:25:41Z.
Review: COMMENTED
I checked that the Windows path now tests the whole page-rounded trap span against the arena's host-region index before creating a trap or applying page protection. That is the same ownership check used by the guest-store path. The existing unknown-region test covers the behavior this fixes. Source review at
67fb3534e1. I did not run the Windows fixture locally.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.