fix(libSceNKWebKit): validate guest pointers in JscDumps exports #27945

Merged
JJenkx merged 2 commits from upstream-pr/27945 into main 2026-12-04 07:06:43 +00:00
JJenkx commented 2026-11-27 21:51:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T21:51:41Z.


What

Validate guest pointers in JSC::CellAttributes::dump and JSC::DOMJIT::HeapRange::dump in core/libs/prx/libSceNKWebKit/src/JscDumps.cpp:

  • Copy CellAttributes and HeapRange self structs through GuestCopyIn_nid_no_patch.
  • Copy WTF::PrintStream vtable pointers and required dispatch slots (PrintStreamVprintf, PrintStreamBegin, PrintStreamEnd) through GuestCopyIn_nid_no_patch with address-overflow checks for both the outer stream and any inner stream returned by Begin, calling NotImplementedAt_nid_no_patch on unmapped, unreadable, or null-slot guest memory while preserving std::invalid_argument for null self, null out, null vtable, and invalid enum values.
  • Record the unmeasured console fault behavior in docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md and add guarded-page and split-page regression tests in core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp.

Tested

  • Linux x86_64 Release (/mnt/sas-ssd/AnyPS5-work/agy/build-spec):
    • Negative control (new TestGuestPointers() against origin/main JscDumps.cpp): ctest --test-dir build-spec -R '^nkwebkit_jscdumps$' --output-on-failure -> failed with SEGFAULT.
    • Candidate (fa7bb2d2149): ctest --test-dir build-spec -R '^nkwebkit_jscdumps$' --output-on-failure -> 1/1 passed (0.01 sec).
    • python3 tools/guest_pointer_audit.py libSceNKWebKit: 0 hits in JscDumps.cpp.
    • python3 tools/check_conventions.py --base origin/main: All conventions checks passed.
    • python3 tools/pr_overlap.py --branch fix/libSceNKWebKit-jsc-dumps-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
    • Dump operations now handle invalid, unreadable, or incomplete memory pointers more safely. These cases no longer rely on direct access to inaccessible data and instead return a consistent unsupported-operation error. Stream printing also completes its cleanup step after printing begins, including when an error occurs.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5533550573 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-27T21:51:41Z. --- ### What Validate guest pointers in `JSC::CellAttributes::dump` and `JSC::DOMJIT::HeapRange::dump` in `core/libs/prx/libSceNKWebKit/src/JscDumps.cpp`: - Copy `CellAttributes` and `HeapRange` `self` structs through `GuestCopyIn_nid_no_patch`. - Copy `WTF::PrintStream` vtable pointers and required dispatch slots (`PrintStreamVprintf`, `PrintStreamBegin`, `PrintStreamEnd`) through `GuestCopyIn_nid_no_patch` with address-overflow checks for both the outer stream and any inner stream returned by `Begin`, calling `NotImplementedAt_nid_no_patch` on unmapped, unreadable, or null-slot guest memory while preserving `std::invalid_argument` for null `self`, null `out`, null `vtable`, and invalid enum values. - Record the unmeasured console fault behavior in `docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md` and add guarded-page and split-page regression tests in `core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp`. ### Tested - Linux x86_64 Release (`/mnt/sas-ssd/AnyPS5-work/agy/build-spec`): - Negative control (new `TestGuestPointers()` against `origin/main` `JscDumps.cpp`): `ctest --test-dir build-spec -R '^nkwebkit_jscdumps$' --output-on-failure` -> failed with `SEGFAULT`. - Candidate (`fa7bb2d2149`): `ctest --test-dir build-spec -R '^nkwebkit_jscdumps$' --output-on-failure` -> 1/1 passed (`0.01 sec`). - `python3 tools/guest_pointer_audit.py libSceNKWebKit`: 0 hits in `JscDumps.cpp`. - `python3 tools/check_conventions.py --base origin/main`: All conventions checks passed. - `python3 tools/pr_overlap.py --branch fix/libSceNKWebKit-jsc-dumps-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** * Dump operations now handle invalid, unreadable, or incomplete memory pointers more safely. These cases no longer rely on direct access to inaccessible data and instead return a consistent unsupported-operation error. Stream printing also completes its cleanup step after printing begins, including when an error occurs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-27 21:53:44 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_jscdumps_tests built cleanly.
  • CTest (nkwebkit_jscdumps):
    1/1 Test #5381: nkwebkit_jscdumps ................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/JscDumps.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5381: nkwebkit_jscdumps ................***Exception: SegFault  0.14 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified GuestCopyIn_nid_no_patch is used on self (CellAttributes and HeapRange) to guard against invalid or boundary-crossing guest pointers.
    • Verified ReadSlot checks out pointer and vtable pointer with GuestCopyIn_nid_no_patch, bounds-checks slot offset against uintptr_t overflow, and validates slot function pointer against null.
    • Verified CheckedBegin, PrintText, and Print consistently validate vtable slots and beginFn/vprintfFn dispatch on both the outer stream and inner stream returned by Begin.
    • Verified technical debt fragment docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md adheres to the repository schema and rules.
    • Verified regression tests in core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp cross-platform guarded pages (VirtualAlloc/mmap) thoroughly test PROT_NONE and split-boundary memory for both dump exports.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093688842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945#pullrequestreview-6093688842). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T21:53:44Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `fa7bb2d214`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_jscdumps_tests` built cleanly. - **CTest** (`nkwebkit_jscdumps`): ``` 1/1 Test #5381: nkwebkit_jscdumps ................ Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/JscDumps.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5381: nkwebkit_jscdumps ................***Exception: SegFault 0.14 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified GuestCopyIn_nid_no_patch is used on self (CellAttributes and HeapRange) to guard against invalid or boundary-crossing guest pointers. - Verified ReadSlot checks out pointer and vtable pointer with GuestCopyIn_nid_no_patch, bounds-checks slot offset against uintptr_t overflow, and validates slot function pointer against null. - Verified CheckedBegin, PrintText, and Print consistently validate vtable slots and beginFn/vprintfFn dispatch on both the outer stream and inner stream returned by Begin. - Verified technical debt fragment docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md adheres to the repository schema and rules. - Verified regression tests in core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp cross-platform guarded pages (VirtualAlloc/mmap) thoroughly test PROT_NONE and split-boundary memory for both dump exports. Looks Good To Me
PrivacyOnion commented 2026-11-27 22:29:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T22:29:09Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: nkwebkit_jscdumps_tests built cleanly.
  • CTest (nkwebkit_jscdumps):
    1/1 Test #5385: nkwebkit_jscdumps ................   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/JscDumps.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5385: nkwebkit_jscdumps ................***Exception: SegFault  0.14 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified null checks on self and out pointers in CellAttributes::dump and HeapRange::dump consistently throw std::invalid_argument before guest memory validation
    • Verified GuestArenaPrepareHostRead_nid_no_patch and GuestReadable_nid_no_patch are executed before GuestCopyIn_nid_no_patch on self, out, and vtable slot pointers
    • Verified 64-bit integer overflow guard on vtable slot pointer arithmetic byteOffset > max - baseAddress before dereference in ReadSlot
    • Verified RAII PrintStreamScope properly guarantees invoking EndFunction(out) even if inner stream dispatch or formatting throws an exception
    • Verified docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md technical debt fragment follows repository format and conventions
    • Verified cross-platform memory protection tests in core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp cover PROT_NONE pages, cross-page boundaries, null vtables, and inner stream scopes on Linux and Windows

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093959312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945#pullrequestreview-6093959312). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T22:29:09Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `aa6df6dd4b`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `nkwebkit_jscdumps_tests` built cleanly. - **CTest** (`nkwebkit_jscdumps`): ``` 1/1 Test #5385: nkwebkit_jscdumps ................ Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/JscDumps.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5385: nkwebkit_jscdumps ................***Exception: SegFault 0.14 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified null checks on self and out pointers in CellAttributes::dump and HeapRange::dump consistently throw std::invalid_argument before guest memory validation - Verified GuestArenaPrepareHostRead_nid_no_patch and GuestReadable_nid_no_patch are executed before GuestCopyIn_nid_no_patch on self, out, and vtable slot pointers - Verified 64-bit integer overflow guard on vtable slot pointer arithmetic byteOffset > max - baseAddress before dereference in ReadSlot - Verified RAII PrintStreamScope properly guarantees invoking EndFunction(out) even if inner stream dispatch or formatting throws an exception - Verified docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md technical debt fragment follows repository format and conventions - Verified cross-platform memory protection tests in core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp cover PROT_NONE pages, cross-page boundaries, null vtables, and inner stream scopes on Linux and Windows Looks Good To Me
Plyxen commented 2026-11-28 05:39:35 +00:00 (Migrated from github.com)

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

Review: APPROVED


Checked head aa6df6dd4b. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main 4c7578e0a4 together with #27997, #27996, #27978, #27975, #27973, #27971, #27969, #27967, #27964, #27958, #27950, #27949, #27946, #27943, #27938, #27936. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. nkwebkit_jscdumps 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:6096092588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945#pullrequestreview-6096092588). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T05:39:35Z. **Review:** APPROVED --- Checked head `aa6df6dd4b`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `4c7578e0a4` together with #27997, #27996, #27978, #27975, #27973, #27971, #27969, #27967, #27964, #27958, #27950, #27949, #27946, #27943, #27938, #27936. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. `nkwebkit_jscdumps` 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:14:14 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

Nothing in the inspected changes shows a verified defect; the candidate tests and checks were not run in this review.

What I ran

  • Read the prepared diff and all three changed files at head aa6df6dd4bd4c424c8c9afe118ed09f0a1e42502 using repo_read.py.
  • No commands or tests were run. The Linux x86_64 test and audit results in the PR description are author-reported.

Results

Check Result Note
Source review passed Three changed files read
Candidate tests not run Author reports 1/1 passed
Negative control not run Author reports a segfault on base

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Tests, audits, and convention checks were not run in this review; their reported results come from the PR description.
  • Console fault behavior remains unmeasured, as recorded in the added debt note.
  • Read: core/libs/prx/libSceNKWebKit/src/JscDumps.cpp, core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp, docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md, plus review/description.md, review/commits.md, review/manifest.json, and review/diff.patch. No changed files were excluded from review.

To get this to a good state

Nothing is required. Optional: run the candidate tests and checks on this exact head, and verify invalid guest-pointer behavior on console hardware.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6096703896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945#pullrequestreview-6096703896). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-28T08:14:14Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing in the inspected changes shows a verified defect; the candidate tests and checks were not run in this review. ## What I ran - Read the prepared diff and all three changed files at head `aa6df6dd4bd4c424c8c9afe118ed09f0a1e42502` using `repo_read.py`. - No commands or tests were run. The Linux x86_64 test and audit results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Three changed files read | | Candidate tests | not run | Author reports 1/1 passed | | Negative control | not run | Author reports a segfault on base | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Tests, audits, and convention checks were not run in this review; their reported results come from the PR description. - Console fault behavior remains unmeasured, as recorded in the added debt note. - Read: `core/libs/prx/libSceNKWebKit/src/JscDumps.cpp`, `core/libs/prx/libSceNKWebKit/tests/JscDumps.cpp`, `docs/dev/debt/changes/fix-libSceNKWebKit-jsc-dumps-guest-pointers.md`, plus `review/description.md`, `review/commits.md`, `review/manifest.json`, and `review/diff.patch`. No changed files were excluded from review. ## To get this to a good state Nothing is required. Optional: run the candidate tests and checks on this exact head, and verify invalid guest-pointer behavior on console hardware.
ligmaSec commented 2026-12-03 08:12:52 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The JSC dump fixture passed for valid output and for rejection of protected or split heap ranges and inaccessible print streams.

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

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165905901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27945#pullrequestreview-6165905901). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T08:12:52Z. **Review:** COMMENTED --- The JSC dump fixture passed for valid output and for rejection of protected or split heap ranges and inaccessible print streams. I ran the exact fixture and changed translation unit 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!27945
No description provided.