fix(libc): accept watched guest pages in the GuestWritable probe #28726
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28726"
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-12-03T07:44:12Z.
What
GuestWritable_nid_no_patchanswers whether the guest could write a range, and libraries use it to refuse a bad output pointer before they do any work. It asks the host for the protection of each page. The write watch makes a guest page read-only on the host between collections, and a read trap makes it inaccessible. So for memory that the guest can write, and that only the driver has protected, the probe answered no and the library call failed.sceSaveDataDirNameSearchinto such a page is one example: it fails although the same call into an unwatched page succeeds.A page that the host reports as not writable is now checked against the guest's own protection:
GuestArenaProtection_nid_postfixgives it for arena memory. Outside the arena, only a page with an armed read trap is accepted.GuestWriteWatchReadTraps_nid_postfix). The Linux write watch doesn't change a page's protection.GuestWriteWatchProtection_nid_postfixgives it.A page that the guest made read-only is still refused, also while it is watched. The probe doesn't resolve a trap and doesn't write anything; the copy after it does that, as before. Because the watch can arm or release a page between the two questions, a refused run is asked for once more before the probe answers no.
The CONVENTIONS paragraph on host writes gets one line, since the probe opens no bracket.
Tested
Correction: the first version of this text said the test passed on Linux. That run was in a tree that also had #28319 merged, and it passed because of that PR. MarcZX10, ligmaSec and CodeRabbit found that the change alone failed there. Head
51ce655c2c0fixes it, and the runs below are on cleanmain(b97867d3ce6) with this branch and my other open libc branches (#28728, #28733 and two more libc++ ones), whose code this change doesn't use.guest_writable_watchpasses, on Linux also withAPS5_NO_PROCMAP_QUERY=1. It covers watched pages, trapped pages, ranges across both, pages the guest made read-only before and after arming, a trapped page the guest made read-only (POSIX), and invalid ranges. It also checks that a write after the probe is recorded and thaterrnois kept.savedata_memory_host_writepasses with a new case that searches save data into watched memory (the test is Windows-only).main'sGeneral.cppand the new tests:guest_writable_watchfails with "a watched page was refused" on Windows and "a trapped page was refused" on Linux, andsavedata_memory_host_writefails with "search into watched memory".General.cpp:guest_writable_watchpasses on Windows and fails on Linux with "a trapped page was refused".tools/pr_overlap.py --branchreports #24415: it changesHostMapping::FindtoFindProtectionon one line of the Linux arm, which is a small textual conflict; neither change needs the other. #9371, #18190 and #27164 conflict withmainand could not be compared, so I read theirGeneral.cpphunks: none touchesGuestWritable.Not tested: macOS (the code is the same question to the same watch, with
mach_vm_regionas before), and a title.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-12-03T07:47:15Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Linux read-trapped pages still fail the new writability probe because the protection query used by this path reports no protection on Linux.
What I ran
Reviewed head
fd4b8a0bdd3277777fc10372f89a729160abd100usingrepo_read.pyand the prepared diff. No tests or other programmatic checks were run.Results
Negative control
Not run. The description reports that the tests fail against the prior implementation; this was not independently verified.
Findings
Blocking
WritableRunreachesWatchedWritablewhen the host mapping is not writable, but the Linux implementation ofGuestWriteWatchProtection_nid_postfixreturns-1without checking trap state. Thus a page madePROT_NONEby a read trap is refused by the probe, including ranges spanning that page. This contradicts the new test’s trapped-page expectations and the PR’s stated behavior. Make the Linux path consult the recorded guest protection and read-trap state before deciding the page is unwritable. General.cpp:992 GuestWriteWatch.cpp:2415Non-blocking
None.
Sources
Not verified
Tests reported in the PR description, macOS behavior, Windows behavior, and runtime behavior on a title were not independently verified. All files listed under
reviewedinfiles.jsonwere read;files.jsonlists no excluded files.To get this to a good state
Implement a Linux protection query that recognizes writable guest pages protected by read traps while continuing to refuse guest read-only pages. Rerun
guest_writable_watchon Linux and Windows andsavedata_memory_host_writeon Windows on the updated head.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T07:52:54Z.
Review: COMMENTED
Actionable comments
92346663-6537-4d93-b372-8ffa3a3c67d2Reviewing files that changed from the base of the PR and between
b97867d3ceandfd4b8a0bdd.core/libs/prx/libc/src/General.cppcore/libs/prx/libc/tests/cmake/guest_writable_watch.cmakecore/libs/tests/GuestWritableWatch.cppcore/libs/tests/SaveDataMemoryHostWrite.cppdocs/dev/CONVENTIONS.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T07:59:38Z.
Review: COMMENTED
The new watched-page fixture still fails on Linux with the exact patched
General.cpplinked against the repository libc. The inline finding identifies the platform branch that leaves read traps rejected.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T09:01:39Z.
Review: COMMENTED
Actionable comments
45d55f8f-9b89-4595-b705-1a55b863f761Reviewing files that changed from the base of the PR and between
fd4b8a0bddand51ce655c2c.core/libs/prx/libc/src/General.cppcore/libs/tests/GuestWritableWatch.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T09:09:23Z.
Review: COMMENTED
Retested
51ce655c2c0on Linux with the exactGeneral.cppandGuestWritableWatchfixture. It passed with the default mapping query and withAPS5_NO_PROCMAP_QUERY=1. The updated code accepts the trapped writable page reported in my earlier review, preserves the trap through the probe, and rejects it after the guest removes write permission.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T09:25:07Z.
Review: APPROVED
Reviewed — looks good
The reviewed head is
51ce655c2c0dee83229810fd331fb6d1c7751da6; the probe preserves guest write permissions while allowing watched or trapped pages, and the added tests cover those cases.What I ran
Reviewed the prepared diff and all five files listed under
reviewedinfiles.json, usingrepo_read.pyat the pinned head for source context. No build or test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Builds and tests were not run in this review. macOS behavior was not independently verified. No changed files were excluded; all five files listed as reviewed were read.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T13:20:59Z.
Review: APPROVED
Reviewed — looks good
The reviewed change has no verified blocking defects, and the inspected code supports merging.
What I ran
Reviewed head
22e684a11b2e8f304f02f110b25e1b7f82d387causingrepo_read.pyand the prepared diff. I did not run tests or compile anything; the test results in the PR description are author-reported.Results
Negative control
Not run by me. The author reports that the control failed on Windows and Linux.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
macOS behavior and the author-reported test runs were not independently verified. All files listed under
reviewedinfiles.jsonwere inspected;files.jsonlists no excluded files.To get this to a good state
Nothing is required.
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.