fix(libSceXml): validate guest handles and roll back failed NodeList allocations #27930
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27930"
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 gurtgg on 2026-11-27T20:32:40Z.
What
XmlHandle*,XmlInitParameter*, and 72-byte block pointer accesses incore/libs/prx/libSceXml/src/NodeList.cpp(NodeListInitialize,NodeListDestroy,NodeListTerminate,NodeListCopy,NodeListIsAvailable,NodeListClear,NodeListInsertFirst,NodeListInsertLast,NodeListRemoveItem,NodeListLength,NodeListItem, andNodeListReplace) usingerrno-preservingGuestCopyIn_nid_no_patch,GuestCopyOut_nid_no_patch, andGuestWritable_nid_no_patchhelpers (CopyInGuest,CopyOutGuest,IsGuestWritable).NodeListblocks ing_liveBlocks(std::unordered_map<void*, LiveBlockEntry>recording trustedNodeListState*and owningconst XmlHandle*underg_liveBlocksMutex), validate the guest-loadedNodeListState*againstLookupLiveState(self.impl)inStateOfbefore any dereference, and atomically claim blocks viaClaimLiveBlock/ClaimOwnedBlockbefore freeing.Attach,NodeListInitialize, andNodeListCopy, pre-checkselfwritability before allocating, register the allocated block underTryRegisterLiveBlockwithLiveBlockGuardinsideBlockGuard, validate block writability before writingNodeListState*, recheckselfwritability viaWriteGuestHandleafter the allocator callback (rolling back on failure), return early on liveself == otherafter writability validation, and release only owned destination blocks (IsOwnedLiveBlock/ClaimOwnedBlock) after replacement succeeds.DestroyNodeList(NodeListDestroy/NodeListTerminate), validateNodeListState*viaStateOf, clearself->implviaWriteGuestHandlebefore claiming and deallocating the block and deletingNodeListState, preventing danglingimplpointers and premature frees on read-only handles.Tested
C:\a5\build, WinLibs GCC 15.2.0) andctest -R "^(guest_xml_|xml_dom_)" --output-on-failure: 10/10 passed (guest_xml_value_types,guest_xml_initializer,xml_dom_parser,xml_dom_reader,guest_xml_document,guest_xml_document_builder,guest_xml_attribute_list,guest_xml_node,guest_xml_node_list,guest_xml_sax_parser).guest_xml_node_listfails (segfault on untrustedNodeListState*) against unmodified1ff8a85636and passes with the fix.TestGuestHandleSafety(core/libs/tests/GuestXmlNodeList.cpp): unreadableXmlHandle*,XmlInitParameter*, and block pointers; read-onlyself/ unwritable 72-byte block rollback; self-copy;errnopreservation.TestCopyIntoLiveDestination(core/libs/tests/GuestXmlNodeList.cpp): transactional allocation failure preservation, live destination replacement, and empty-source copy cleanup.TestInvalidStoredStatePointer(core/libs/tests/GuestXmlNodeList.cpp): fake readable block with bogus/nullNodeListState*, corrupted live block state pointer (preserving state until restored), and terminated stale block rejection.TestCopyOwnershipPreservesAliasedBlock(core/libs/tests/GuestXmlNodeList.cpp): copying live or empty handles into an unowned aliasedXmlHandlepreserves the original owner's live block and items.TestAttachPostAllocateReadOnlyRollback(core/libs/tests/GuestXmlNodeList.cpp):Attachrolls back and unregisters the allocated block whenselfbecomes read-only during the allocator callback.Checklist
main; no other open PR implements the same functionstools/check_conventions.pypasses)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositorymainand passes after fixSummary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T20:38:41Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
205741c9bf:tools/check_conventions.pypassed.guest_xml_node_list_testsbuilt cleanly.guest_xml_node_list):core/libs/prx/libSceXml/src/NodeList.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T20:41:05Z.
Review: COMMENTED
Actionable comments posted: 2
28963400-2f88-4e39-b66c-251f5db78ca1Reviewing files that changed from the base of the PR and between
fdf873a7d2and205741c9bf.core/libs/prx/libSceXml/src/NodeList.cppcore/libs/tests/GuestXmlNodeList.cppLimit details: You’ve used all 10 included reviews currently available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T20:50:07Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes blocks merging; the new guest-memory guards and allocation rollback are consistent with the helper APIs and the existing NodeList behavior.
What I ran
Reviewed head
205741c9bfaa77a314dafa5273d8da427cdb1421from the prepared diff and read the full text of both changed files. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The test suite and platform builds were not run. No files were excluded:
manifest.jsonmarks both changed files as included;files.jsonwas not available in the review bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T21:07:48Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
71b0a29584:tools/check_conventions.pypassed.guest_xml_node_list_testsbuilt cleanly.guest_xml_node_list):core/libs/prx/libSceXml/src/NodeList.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T21:21:15Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure the
NodeListCopyself-copy path validates that the guest handle can be written without attempting to open a write mapping for a read-only page.What I ran
Reviewed head
71b0a295842a2d17e7db0ba51e2de5d087759feffrom the prepared diff and read the full text of both changed files. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libSceXml/src/NodeList.cpp:183—NodeListCopycallsIsGuestWritableon a read-only live self handle.IsGuestWritablefirst constructsGuestArena::HostWritefor that address (NodeList.cpp:38), before querying writability. The new test invokes this path on a read-only page (core/libs/tests/GuestXmlNodeList.cpp:531). If openingHostWritechanges page protection or fails to preserve the original protection, the self-copy check can fault or alter the page state. Check writability without acquiring a write mapping, or otherwise ensure the mapping is safely released before returning.Non-blocking
None.
Not verified
To get this to a good state
GuestXmlNodeListtest.Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:05:57Z.
Review: APPROVED
Checked head
71b0a29584. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomaina163d4b886together with #27929, #27926, #27925, #27924, #27923, #27922, #27901, #27828, #27771, #27755, #27748, #27682, #27765.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded.guest_xml_node_listpasses. In the full CPU suite (5,120 tests) the only failures are unrelated:windows_read_trap_unknownfails onmaintoo (fixed in #28028).frame_capture_minimize,jpeg_external_toolchainandguest_pthread_mutex_contentionare timeouts under load; they pass when run on their own.guest_audio_in_capturepasses 20/20 onmainand with #27922.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T02:06:15Z.
Review: COMMENTED
Actionable comments posted: 1
503390b2-1041-46ea-9fbe-c601ec560c9bReviewing files that changed from the base of the PR and between
71b0a29584andd2c8e666fc.core/libs/prx/libSceXml/src/NodeList.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T02:09:37Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge:
NodeListCopycan overwrite an already-live destination handle without releasing its existing block and state.What I ran
Reviewed head
d2c8e666fc20667c52938075fc61d22c50c9760f. No tests or build commands were run.Results
Findings
Blocking
core/libs/prx/libSceXml/src/NodeList.cpp:183— Whenselfalready owns a live list andotheris a different live list,Attachinstalls a newly allocated block intoselfwithout freeing the old block or deleting itsNodeListState. This leaks both resources on copy assignment/construction into a live destination. Preserve the existing destination state or destroy it safely before replacing the handle, and add regression coverage for copying into an already-live destination.Non-blocking
None.
Not verified
No tests, build, or runtime checks were run. Both changed files were read:
core/libs/prx/libSceXml/src/NodeList.cppandcore/libs/tests/GuestXmlNodeList.cpp; neither changed file was excluded.To get this to a good state
Fix replacement of an already-live destination in
NodeListCopy, with regression coverage, then rerun the relevant XML NodeList tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T16:37:41Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The block read verifies that
self.implpoints to readable memory, but the state pointer loaded from that memory is dereferenced without validation.What I ran
Reviewed head
1ff8a8563680351c8e48b1c3752beba025a5d21ausing the prepared diff and manifest, plus targeted source reads throughrepo_read.py. No build or test was run. The reader returned source content, then reported that it could not write its read log because the run directory is read-only.Results
Source reads
Negative control
Not run; the regression tests were not executed because their compile requirements were not established. The test claims in the PR description are author-reported.
Findings
Blocking
core/libs/prx/libSceXml/src/NodeList.cpp:83reads aNodeListState*from the guest block but does not verify that the pointer is valid before callers dereference it. A readable block containing an invalid pointer can still crash operations such asclearorterminate, defeating the guest-handle safety change. Validate the loaded state pointer against trusted ownership before using it, and add a regression case for a readable block containing an invalid state pointer. Source at the reviewed commitNon-blocking
None.
Sources
Reviewed the changed hunks in
core/libs/prx/libSceXml/src/NodeList.cppandcore/libs/tests/GuestXmlNodeList.cpp; both files were included, andfiles.jsonlists no exclusions. The implementation’sStateOfreads the stored pointer at the cited lines;RequireLiveStatereturns it for subsequent use at lines 93–97.Not verified
The regression tests and build were not run. The full behavior of the guest memory helpers was not independently verified. No files were excluded by the supplied manifest.
To get this to a good state
Validate the loaded
NodeListState*before any dereference, add a regression test for a readable block with an invalid stored state pointer, and rerun the relevant tests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T16:40:30Z.
Review: COMMENTED
🏛️ Architecture findings (2)
Advisory architecture findings (1)
💬 Code review
Actionable comments posted (2)
502eb3eb-bb80-42cf-b7af-e93959d99cedReviewing files that changed from the base of the PR and between
d2c8e666fcand1ff8a85636.core/libs/prx/libSceXml/src/NodeList.cppcore/libs/tests/GuestXmlNodeList.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T11:15:19Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure destroying a non-owning alias cannot free another handle’s live NodeList block.
What I ran
Reviewed head
049fc0ac85a8160ebc4bfed57706b037ebffc751. Read the changed source through the pinnedrepo_read.pyreader and inspected the prepared diff and test file. No tests were run by me.Results
Negative control
Not run by me; the negative control result is author-reported.
Findings
Blocking
core/libs/prx/libSceXml/src/NodeList.cpp:226:DestroyNodeListcallsClaimLiveBlockwithout checking thatselfowns the registered block. If a second handle aliases a live handle’simpl, destroying the alias claims and frees the original handle’s block while the original still points to it. Require ownership when claiming for destruction, and define safe behavior for an unowned alias. Add a regression test that destroys an alias and confirms the owner remains valid.Non-blocking
None.
Sources
Not verified
No tests or builds were run by me; Windows behavior and the author-reported results were not independently confirmed. Both changed files listed in the manifest were reviewed; no files were excluded by rule.
To get this to a good state
Make destruction ownership-aware and add the alias-destruction regression test. Rerun the reported
guest_xml_andxml_dom_test selection on the new head.Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T11:22:50Z.
Review: COMMENTED
Actionable comments
31e93a10-0788-4621-a40c-7cb28489b741Reviewing files that changed from the base of the PR and between
1ff8a85636and049fc0ac85.core/libs/prx/libSceXml/src/NodeList.cppcore/libs/tests/GuestXmlNodeList.cppIncluded 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-03T09:18:04Z.
Review: COMMENTED
The Linux
guest_xml_node_listCTest passed with the rebuilt XML library. The fixture checks list contents and references through successful operations and the new allocation-failure cases that exercise rollback.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T16:14:41Z.
Review: APPROVED
Re-verified head
049fc0ac85on Windows 11 with WinLibs GCC 15.2 (Release), applied alone to main484b0368d3. That covers the three commits since my last review: the writability query withoutHostWrite, releasing the destination only after the copy succeeds, and validating the storedNodeListStatepointers.guest_xml_node_listpasses, as on main.NodeList.cppreverted to main and the tests kept: the test crashes inlibSceXml.prxon a read of an unmapped guest page (0x391000).Not run: Linux and macOS.
AI-assisted: yes (Claude Code)
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.