fix(libSceNKWebKit): validate guest pointers in JscObject exports #27975

Merged
JJenkx merged 1 commit from upstream-pr/27975 into main 2026-12-04 07:14:58 +00:00
JJenkx commented 2026-11-27 23:55:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T23:55:42Z.


What

Validate guest memory reads and writes across JscObject exports in core/libs/prx/libSceNKWebKit/src/JscObject.cpp:

  • Validate and copy JSClassDefinition, className, staticValues / staticFunctions arrays and name strings, and guard parentClass refcount updates in JSClassCreate (using a scoped OpaqueJSClass deleter so failed mid-copy guest reads leak nothing).
  • Guard OpaqueJSClass::~OpaqueJSClass (D1Ev/D2Ev) with active GuestArena::HostWrite + readability/writability checks.
  • Validate guest parameterNames readability before allocating host snapshots in JSObjectMakeFunction, and validate guest arguments readability before allocating argument vectors in JSObjectMakeArray, JSObjectMakeDate, JSObjectMakeError, JSObjectMakeRegExp, JSObjectCallAsFunction, and JSObjectCallAsConstructor.
  • Guard both resolve and reject output pointers with active GuestArena::HostWrite scopes before calling JS_NewPromiseCapability and write them via GuestCopyOut_nid_no_patch in JSObjectMakeDeferredPromise.
  • Route JSValueRef* exception output writes across JscObject.cpp (including JSObjectMakeTypedArrayWithBytesNoCopy) through active GuestArena::HostWrite + GuestWritable_nid_no_patch + GuestCopyOut_nid_no_patch.
  • Add guarded/read-only page negative-control tests (TestGuestPointers) in core/libs/prx/libSceNKWebKit/tests/JscMakeObjects.cpp and record the unmeasured console fault behavior in docs/dev/debt/changes/fix-libSceNKWebKit-jsc-object-guest-pointers.md.

Tested

  • Linux (Release):
    • Negative control (new TestGuestPointers tests in JscMakeObjects.cpp against unmodified JscObject.cpp): nkwebkit_jscmakeobjects failed with ***Exception: SegFault (0/1 passed).
    • Candidate: built 8 JSC test targets (nkwebkit_jsc, nkwebkit_jscclasscallbacks, nkwebkit_jscclassprototype, nkwebkit_jscconstructor, nkwebkit_jscfinalize, nkwebkit_jscglobalclassrelease, nkwebkit_jscmakeobjects, nkwebkit_jscobjectextensibility); ctest passed (8/8, 0.23 sec).
    • python3 tools/guest_pointer_audit.py libSceNKWebKit reports 0 direct guest pointer accesses in src/JscObject.cpp.
    • python3 tools/check_conventions.py --base origin/main passed.
    • python3 tools/pr_overlap.py --branch fix/libSceNKWebKit-jsc-object-guest-pointers: No overlap with open pull requests.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid or inaccessible memory in JavaScriptCore object and promise APIs. Calls with invalid inputs or unwritable output locations now fail safely, and failed promise operations leave output values unchanged.
    • Added checks for guest-provided structures, strings, argument lists, and exception outputs to help prevent unsafe memory access.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5534660559 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27975). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T23:55:42Z. --- ### What Validate guest memory reads and writes across `JscObject` exports in `core/libs/prx/libSceNKWebKit/src/JscObject.cpp`: - Validate and copy `JSClassDefinition`, `className`, `staticValues` / `staticFunctions` arrays and name strings, and guard `parentClass` refcount updates in `JSClassCreate` (using a scoped `OpaqueJSClass` deleter so failed mid-copy guest reads leak nothing). - Guard `OpaqueJSClass::~OpaqueJSClass` (`D1Ev`/`D2Ev`) with active `GuestArena::HostWrite` + readability/writability checks. - Validate guest `parameterNames` readability before allocating host snapshots in `JSObjectMakeFunction`, and validate guest `arguments` readability before allocating argument vectors in `JSObjectMakeArray`, `JSObjectMakeDate`, `JSObjectMakeError`, `JSObjectMakeRegExp`, `JSObjectCallAsFunction`, and `JSObjectCallAsConstructor`. - Guard both `resolve` and `reject` output pointers with active `GuestArena::HostWrite` scopes before calling `JS_NewPromiseCapability` and write them via `GuestCopyOut_nid_no_patch` in `JSObjectMakeDeferredPromise`. - Route `JSValueRef* exception` output writes across `JscObject.cpp` (including `JSObjectMakeTypedArrayWithBytesNoCopy`) through active `GuestArena::HostWrite` + `GuestWritable_nid_no_patch` + `GuestCopyOut_nid_no_patch`. - Add guarded/read-only page negative-control tests (`TestGuestPointers`) in `core/libs/prx/libSceNKWebKit/tests/JscMakeObjects.cpp` and record the unmeasured console fault behavior in `docs/dev/debt/changes/fix-libSceNKWebKit-jsc-object-guest-pointers.md`. ### Tested - Linux (Release): - Negative control (new `TestGuestPointers` tests in `JscMakeObjects.cpp` against unmodified `JscObject.cpp`): `nkwebkit_jscmakeobjects` failed with `***Exception: SegFault` (0/1 passed). - Candidate: built 8 JSC test targets (`nkwebkit_jsc`, `nkwebkit_jscclasscallbacks`, `nkwebkit_jscclassprototype`, `nkwebkit_jscconstructor`, `nkwebkit_jscfinalize`, `nkwebkit_jscglobalclassrelease`, `nkwebkit_jscmakeobjects`, `nkwebkit_jscobjectextensibility`); `ctest` passed (`8/8`, `0.23 sec`). - `python3 tools/guest_pointer_audit.py libSceNKWebKit` reports 0 direct guest pointer accesses in `src/JscObject.cpp`. - `python3 tools/check_conventions.py --base origin/main` passed. - `python3 tools/pr_overlap.py --branch fix/libSceNKWebKit-jsc-object-guest-pointers`: `No overlap with open pull requests.` ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of invalid or inaccessible memory in JavaScriptCore object and promise APIs. Calls with invalid inputs or unwritable output locations now fail safely, and failed promise operations leave output values unchanged. * Added checks for guest-provided structures, strings, argument lists, and exception outputs to help prevent unsafe memory access. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-27 23:56:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T23:56:53Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against a934c5159c:

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_jscmakeobjects_tests built cleanly.
  • CTest (nkwebkit_jscmakeobjects):
    1/1 Test #5392: nkwebkit_jscmakeobjects ..........   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/JscObject.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5392: nkwebkit_jscmakeobjects ..........***Exception: SegFault  0.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that StoreGuestPointer, CaptureGuestException, and SetGuestExceptionValue validate destination write permissions via GuestArena::HostWrite, GuestWritable_nid_no_patch, and GuestCopyOut_nid_no_patch across all JSObjectMake* and property exports in JscObject.cpp.
    • Checked JSClassCreate and DestroyJSClass for guest memory bounds and pointer safety, verifying that def.parentClass refCount mutations and OpaqueJSClass destruction open active HostWrite scopes and handle null checks properly.
    • Audited argument array copying in CopyGuestArguments and JSObjectMakeFunction parameterNames, verifying that integer overflows (count * sizeof(T)) and null/invalid guest pointer buffers trigger NotImplementedAt_nid_no_patch without leaking or crashing.
    • Verified that JSObjectMakeDeferredPromise properly opens HostWrite scopes for resolve and reject out-pointers prior to calling JS_NewPromiseCapability, and safely releases promise resources on failure.
    • Confirmed full compliance with AGENTS.md conventions, including zero forbidden comments, proper debt tracking fragment in docs/dev/debt/changes/fix-libSceNKWebKit-jsc-object-guest-pointers.md, and comprehensive negative control tests.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6094455653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27975#pullrequestreview-6094455653). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T23:56:53Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a934c5159c`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_jscmakeobjects_tests` built cleanly. - **CTest** (`nkwebkit_jscmakeobjects`): ``` 1/1 Test #5392: nkwebkit_jscmakeobjects .......... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/JscObject.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5392: nkwebkit_jscmakeobjects ..........***Exception: SegFault 0.13 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified that StoreGuestPointer, CaptureGuestException, and SetGuestExceptionValue validate destination write permissions via GuestArena::HostWrite, GuestWritable_nid_no_patch, and GuestCopyOut_nid_no_patch across all JSObjectMake* and property exports in JscObject.cpp. - Checked JSClassCreate and DestroyJSClass for guest memory bounds and pointer safety, verifying that def.parentClass refCount mutations and OpaqueJSClass destruction open active HostWrite scopes and handle null checks properly. - Audited argument array copying in CopyGuestArguments and JSObjectMakeFunction parameterNames, verifying that integer overflows (count * sizeof(T)) and null/invalid guest pointer buffers trigger NotImplementedAt_nid_no_patch without leaking or crashing. - Verified that JSObjectMakeDeferredPromise properly opens HostWrite scopes for resolve and reject out-pointers prior to calling JS_NewPromiseCapability, and safely releases promise resources on failure. - Confirmed full compliance with AGENTS.md conventions, including zero forbidden comments, proper debt tracking fragment in docs/dev/debt/changes/fix-libSceNKWebKit-jsc-object-guest-pointers.md, and comprehensive negative control tests. Looks Good To Me
Plyxen commented 2026-11-28 05:39:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T05:39:09Z.

Review: APPROVED


Checked head a934c5159c. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main 4c7578e0a4 together with #27997, #27996, #27978, #27973, #27971, #27969, #27967, #27964, #27958, #27950, #27949, #27946, #27945, #27943, #27938, #27936. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. nkwebkit_jscmakeobjects passes. In the full CPU suite (5,131 tests) the only failures are unrelated: windows_read_trap_unknown fails on main too (fixed in #28028), and frame_capture_minimize is a timeout under load that passes on its own.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096090290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27975#pullrequestreview-6096090290). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T05:39:09Z. **Review:** APPROVED --- Checked head `a934c5159c`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `4c7578e0a4` together with #27997, #27996, #27978, #27973, #27971, #27969, #27967, #27964, #27958, #27950, #27949, #27946, #27945, #27943, #27938, #27936. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. `nkwebkit_jscmakeobjects` passes. In the full CPU suite (5,131 tests) the only failures are unrelated: `windows_read_trap_unknown` fails on `main` too (fixed in #28028), and `frame_capture_minimize` is a timeout under load that passes on its own. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-28 08:26:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T08:26:02Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the documented console behavior remains unmeasured, and I did not run the supplied Linux checks.

What I ran

Read the prepared diff and changed files at head a934c5159c9d51376df668de2886fb23d5157641. No commands or tests were run.

Results

Check Result Note
Diff and code review passed Changed code reviewed
Supplied Linux checks not run Reported by author only
Console fault behavior not run Documented as unmeasured

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports a passing Linux build/test run and pointer audit; these were not independently run. Console behavior is unmeasured. Read: JscObject.cpp, JscMakeObjects.cpp, and the new debt note. No changed file was excluded; all three manifest entries were included and read. files.json was unavailable through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096756931 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27975#pullrequestreview-6096756931). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T08:26:02Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the documented console behavior remains unmeasured, and I did not run the supplied Linux checks. ## What I ran Read the prepared diff and changed files at head `a934c5159c9d51376df668de2886fb23d5157641`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and code review | passed | Changed code reviewed | | Supplied Linux checks | not run | Reported by author only | | Console fault behavior | not run | Documented as unmeasured | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports a passing Linux build/test run and pointer audit; these were not independently run. Console behavior is unmeasured. Read: `JscObject.cpp`, `JscMakeObjects.cpp`, and the new debt note. No changed file was excluded; all three manifest entries were included and read. `files.json` was unavailable through the reader. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 08:17:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:17:04Z.

Review: COMMENTED


The JSC object fixture passed with the pinned QuickJS library. It covered array, Date, Error and RegExp construction with guarded argument vectors, function and constructor calls, and a property getter that throws while the exception output is read-only.

I compiled the changed translation unit and exact fixture in a focused Linux build linked against the project’s guest libraries.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165957480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27975#pullrequestreview-6165957480). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T08:17:04Z. **Review:** COMMENTED --- The JSC object fixture passed with the pinned QuickJS library. It covered array, Date, Error and RegExp construction with guarded argument vectors, function and constructor calls, and a property getter that throws while the exception output is read-only. I compiled the changed translation unit and exact fixture in a focused Linux build linked against the project’s guest libraries. AI-assisted: yes.
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!27975
No description provided.