fix(libSceNKWebKit): validate guest pointers in CrossThreadTaskHandler exports #27938
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27938"
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 JJenkx on 2026-11-27T21:03:50Z.
What
Validate guest pointers in
WTF::CrossThreadTaskHandlerconstructors (C1/C2), destructors (D0/D1/D2),postTask,postTaskReply, andkillincore/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cpp:CrossThreadTaskHandlerunderGuestArena::HostWritein constructors and destructors, copy handler fields throughGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patchwhile preservingunused[96]bytes16..111, and clean up the worker thread and state if publishing the constructed header fails.CrossThreadTaskHandlerStateinstances in a synchronized live-state registry and reference-countedStateRefso forged or stalestatepointers are rejected withNotImplementedAt_nid_no_patchbefore accessing internal mutexes or queues.VoidFunctionwrappers and callable vtables (callanddeletingDestructor) viaGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patchinpostTask,postTaskReply,Destroy, andRunTaskscompletion dispatch.docs/dev/debt/changes/fix-libSceNKWebKit-cross-thread-task-handler-guest-pointers.mdand add guarded-page, read-only, split-page, forged-state, and invalid-callable regression tests incore/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cpp.Tested
/mnt/sas-ssd/AnyPS5-work/agy/build-spec):TestGuestPointers()againstorigin/mainCrossThreadTaskHandler.cpp):ctest --test-dir build-spec -R '^nkwebkit_crossthreadtaskhandler$' --output-on-failure-> failed withSEGFAULT.5a1d9190e17):ctest --test-dir build-spec -R '^nkwebkit_crossthreadtaskhandler$' --output-on-failure-> 1/1 passed (0.81 sec).python3 tools/guest_pointer_audit.py libSceNKWebKit: 0 hits inCrossThreadTaskHandler.cpp.python3 tools/check_conventions.py --base origin/main: All conventions checks passed.python3 tools/pr_overlap.py --branch fix/libSceNKWebKit-cross-thread-task-handler-guest-pointers: No overlap with open pull requests.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T21:06:14Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
5a1d9190e1:tools/check_conventions.pypassed.nkwebkit_crossthreadtaskhandler_testsbuilt cleanly.nkwebkit_crossthreadtaskhandler):core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.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-27T21:12:20Z.
Review: COMMENTED
Actionable comments posted: 6
47a9ee4a-295b-4778-962e-b99d755ace70Reviewing files that changed from the base of the PR and between
335fd4626fand5a1d9190e1.core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cppcore/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cppdocs/dev/debt/changes/fix-libSceNKWebKit-cross-thread-task-handler-guest-pointers.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T21:37:13Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
40fa84137c:tools/check_conventions.pypassed.nkwebkit_crossthreadtaskhandler_testsbuilt cleanly.nkwebkit_crossthreadtaskhandler):core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.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:41:12Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: preserve the state reference across concurrent destruction and make enqueue publication exception-safe.
What I ran
40fa84137c99320be639fe8cfdf4d3d5a8edd6a9usingrepo_read.py.core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cpp,core/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cpp, anddocs/dev/debt/changes/fix-libSceNKWebKit-cross-thread-task-handler-guest-pointers.md.files.json; its file list was confirmed with the review folder listing.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cpp:334checks registry membership underLiveStatesLock, then drops that lock before reading or retainingstate. ConcurrentDestroycan erase the entry, release the handler’s final reference at line 379, and freestatebefore thisDestroycaller locks its mutex at line 368. The same check-then-use race exists inAcquireLiveStateat lines 173–177: it incrementsreferencesonly after finding the pointer, butDestroycan remove and release the state after the lookup unlocks, allowing a stale-pointer dereference. Keep state lifetime pinned atomically with registry validation and prevent overlapping destruction from proceeding on the same state.core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cpp:400clears the guestVoidFunctionbeforedeque::push_backsucceeds. If allocation throws, the callable is no longer owned by the caller and is not queued, leaking it.PostTaskReplyImplhas the same ordering at lines 424–429; after queue insertion, allocation ofReplyJobcan also throw withreplyScheduledleft true and no job scheduled, stranding queued replies. Restore caller ownership on failed enqueue and roll back reply scheduling/queue state on job allocation or scheduling failure.Non-blocking
Not verified
To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T21:45:20Z.
Review: COMMENTED
Actionable comments posted: 1
b8ca2d79-b591-4a7b-b947-6a119379b939Reviewing files that changed from the base of the PR and between
5a1d9190e1and40fa84137c.core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cppcore/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cppdocs/dev/debt/changes/fix-libSceNKWebKit-cross-thread-task-handler-guest-pointers.mdIncluded 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 PrivacyOnion on 2026-11-27T21:57:17Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
68bb320d36:tools/check_conventions.pypassed.nkwebkit_crossthreadtaskhandler_testsbuilt cleanly.nkwebkit_crossthreadtaskhandler):core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.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-27T22:03:13Z.
Review: COMMENTED
c9c07623-a84d-4a4b-9fcf-e0964ec0aed7Reviewing files that changed from the base of the PR and between
40fa84137cand68bb320d36.core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cppcore/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:39:41Z.
Review: APPROVED
Checked head
68bb320d36. All on Windows 11 with WinLibs GCC 15.2 (Release), applied tomain4c7578e0a4together with #27997, #27996, #27978, #27975, #27973, #27971, #27969, #27967, #27964, #27958, #27950, #27949, #27946, #27945, #27943, #27936.tools/check_conventions.py --headandtools/debt_fold.py --checkpassed and the full build succeeded.nkwebkit_crossthreadtaskhandlerpasses, including the destroy race case. I also checked68bb320d36against both blocking findings on40fa84137c.AcquireLiveStateandDestroynow take their reference underLiveStatesLock, andDestroymarks the state retiring before it drops the lock.PostTaskImplandPostTaskReplyImplpush the callable before clearing the guestVoidFunction.PostTaskReplyImplallocates theReplyJobbefore queueing, and rolls backreplyScheduledand the queued reply ifcallOnMainThreadthrows. In the full CPU suite (5,131 tests) the only failures are unrelated:windows_read_trap_unknownfails onmaintoo (fixed in #28028), andframe_capture_minimizeis a timeout under load that passes on its own.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T06:38:27Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed source, tests, and debt note were read at the pinned head; no blocking defect was verified, but executable checks were not run in this review.
What I ran
Read the prepared diff and all three changed files at head
68bb320d36739e6c1d3dc10e42ffd395937610dbusingrepo_read.py. No commands or tests were run. The description reports Linux x86_64 Release test and audit results; these were not independently verified.Results
Findings
Blocking
None verified.
Non-blocking
No additional code feedback. The PR records console fault behavior as unmeasured; verifying it on hardware would close that documented debt.
Not verified
The Linux test, guest pointer audit, conventions check, overlap check, and console behavior were not run or independently confirmed. All three changed files were read:
core/libs/prx/libSceNKWebKit/src/CrossThreadTaskHandler.cpp,core/libs/prx/libSceNKWebKit/tests/CrossThreadTaskHandler.cpp, anddocs/dev/debt/changes/fix-libSceNKWebKit-cross-thread-task-handler-guest-pointers.md. The manifest lists no excluded changed files.To get this to a good state
Nothing is required. Optional: verify the documented guest pointer fault behavior on console hardware.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:12:55Z.
Review: COMMENTED
The cross-thread fixture passed normal task handling and the new ownership checks. Two concurrent destructor attempts produced one success and one rejection, with no remaining live callable.
I ran the exact fixture and changed translation unit in a focused Linux build linked against the project’s guest libraries.
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.