fix(libkernel): return EFAULT for unusable JIT shared-memory pointers #14497

Merged
fogydes merged 1 commit from upstream-pr/14497 into main 2026-11-14 10:19:38 +00:00
fogydes commented 2026-11-01 15:16:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-11-01T15:16:13Z.


What

Guard the JIT shared-memory output and in/out pointer copies. Creation and alias creation close the newly registered descriptor if fdOut cannot be written. Mapping reads startOut through checked copyin and rolls back the mapping if copyout fails. EFAULT on unusable memory is a documented host-safety fallback, not a console measurement.

Preserve g_jitLock through descriptor lookup, permission checks, duplication and DoMapShared so concurrent close cannot invalidate or reuse the descriptor before use. Release that lock before guest copyout and rollback. Rebased onto current main cacaa4a5ec; only Jit.cpp, the focused regression test and its debt entry differ.

Tested

  • Windows 11 x64, WinLibs MinGW/GCC 15.2, full Release configuration: affected libc/libkernel and guest_jit_shared_memory_tests built in a dedicated D-drive tree. guest_jit_shared_memory passed 1/1 on final rebased head f86d7e4988 (0.85s).
  • Tests exercise unusable fdOut/startOut plus a readonly startOut page after successful mapping, descriptor/mapping rollback and existing permission/alias behavior.
  • Public headers: 413 libraries / 34,548 exports passed. Current conventions, git diff --check and git merge-tree against main cacaa4a5ec passed.
  • Earlier negative-control and peer-run evidence belongs to the corresponding older heads; it is not claimed freshly reproduced here. No console/title/GPU behavior or speed claim.

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
  • 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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5108675453 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14497). Originally posted by [fogydes](https://github.com/fogydes) on 2026-11-01T15:16:13Z. --- ### What Guard the JIT shared-memory output and in/out pointer copies. Creation and alias creation close the newly registered descriptor if fdOut cannot be written. Mapping reads startOut through checked copyin and rolls back the mapping if copyout fails. EFAULT on unusable memory is a documented host-safety fallback, not a console measurement. Preserve g_jitLock through descriptor lookup, permission checks, duplication and DoMapShared so concurrent close cannot invalidate or reuse the descriptor before use. Release that lock before guest copyout and rollback. Rebased onto current main cacaa4a5ecb; only Jit.cpp, the focused regression test and its debt entry differ. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Windows 11 x64, WinLibs MinGW/GCC 15.2, full Release configuration: affected libc/libkernel and guest_jit_shared_memory_tests built in a dedicated D-drive tree. guest_jit_shared_memory passed **1/1** on final rebased head f86d7e4988c (0.85s). - Tests exercise unusable fdOut/startOut plus a readonly startOut page after successful mapping, descriptor/mapping rollback and existing permission/alias behavior. - Public headers: **413 libraries / 34,548 exports** passed. Current conventions, git diff --check and git merge-tree against main cacaa4a5ecb passed. - Earlier negative-control and peer-run evidence belongs to the corresponding older heads; it is not claimed freshly reproduced here. No console/title/GPU behavior or speed claim. ### 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) - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-11-02 04:59:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:59:10Z.

Review: COMMENTED


Reviewed — no blocking findings

The three JIT shared-memory calls now copy their arguments in and out with GuestCopyIn/GuestCopyOut and return EFAULT for an unreadable or unwritable pointer. On the two failure paths after a descriptor is created, the code closes the new descriptor, and close_nid_postfix forgets the JIT entry (Stdio.cpp line 811), so no stale registry entry is left. The map path unmaps the new mapping when the copy-out fails. The guest test did not run hosted: its CTest run has one tool case.

What I ran

  • Head d255b6d1840eb9bedadab87811964920d2b2bc1f; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 3 files, +53/-23: core/libs/prx/libkernel/DirectMemory/Jit.cpp, core/libs/tests/GuestJitSharedMemory.cpp (+10) and docs/dev/debt/libkernel.md (+1). The test is registered as guest_jit_shared_memory_tests (libkernel/CMakeLists.txt line 1580).
  • Read the full Jit.cpp diff for create, alias and map, and the close path that forgets the descriptor (File/src/Stdio.cpp lines 796-811 and ForgetJitSharedMemory at Jit.cpp line 178).
  • Read the new test assertions, including the read-only page case for map.
  • Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed; the ABI audit is not applicable (no exported symbol changed).
  • Hosted: the windows CTest run has one case, a tool check. guest_jit_shared_memory was not in the run.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Create and alias failure after insert passed close_nid_postfix forgets the entry (Stdio.cpp line 811)
Map failure after mapping passed sceKernelMunmap undoes the mapping (read)
EFAULT for unreadable or unwritable pointers passed read; test assertions match
guest_jit_shared_memory (hosted) not run not in the Windows CTest run
Build and runtime tests not run no local build
Negative controls not run no local build
Hosted CI passed windows passed (one tool case); linux and relinkers skipped
Read-only check output

Precheck was not run: no PR-head code is run here. Conventions: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/d255b6d1840eb9bedadab87811964920d2b2bc1f/check-runs.

Negative control

Not run here. A negative control needs a build, and code from this head is not run here.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

  • The guest test did not run hosted.
  • The Linux behaviour was not checked.

To get this to a good state

  • Nothing to change. Running the guest test once on the hosted runner would confirm the new assertions.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732260185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14497#pullrequestreview-5732260185). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:59:10Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The three JIT shared-memory calls now copy their arguments in and out with `GuestCopyIn`/`GuestCopyOut` and return EFAULT for an unreadable or unwritable pointer. On the two failure paths after a descriptor is created, the code closes the new descriptor, and `close_nid_postfix` forgets the JIT entry (`Stdio.cpp` line 811), so no stale registry entry is left. The map path unmaps the new mapping when the copy-out fails. The guest test did not run hosted: its CTest run has one tool case. ## What I ran - Head `d255b6d1840eb9bedadab87811964920d2b2bc1f`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 3 files, +53/-23: `core/libs/prx/libkernel/DirectMemory/Jit.cpp`, `core/libs/tests/GuestJitSharedMemory.cpp` (+10) and `docs/dev/debt/libkernel.md` (+1). The test is registered as `guest_jit_shared_memory_tests` (`libkernel/CMakeLists.txt` line 1580). - Read the full `Jit.cpp` diff for create, alias and map, and the close path that forgets the descriptor (`File/src/Stdio.cpp` lines 796-811 and `ForgetJitSharedMemory` at `Jit.cpp` line 178). - Read the new test assertions, including the read-only page case for map. - Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed; the ABI audit is not applicable (no exported symbol changed). - Hosted: the windows CTest run has one case, a tool check. `guest_jit_shared_memory` was not in the run. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | depends on none; the stack check passed | | Create and alias failure after insert | passed | `close_nid_postfix` forgets the entry (`Stdio.cpp` line 811) | | Map failure after mapping | passed | `sceKernelMunmap` undoes the mapping (read) | | EFAULT for unreadable or unwritable pointers | passed | read; test assertions match | | `guest_jit_shared_memory` (hosted) | not run | not in the Windows CTest run | | Build and runtime tests | not run | no local build | | Negative controls | not run | no local build | | Hosted CI | passed | windows passed (one tool case); linux and relinkers skipped | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Conventions: passed. Hosted: `gh api repos/boykopovar/AnyPS5/commits/d255b6d1840eb9bedadab87811964920d2b2bc1f/check-runs`. </details> ## Negative control Not run here. A negative control needs a build, and code from this head is not run here. ## Findings **Blocking** None. **Non-blocking** None. ## Sources - Create, alias and map: https://github.com/boykopovar/AnyPS5/blob/d255b6d1840eb9bedadab87811964920d2b2bc1f/core/libs/prx/libkernel/DirectMemory/Jit.cpp - Close path: https://github.com/boykopovar/AnyPS5/blob/f2d874c1fdccf781c0fa5d86619bb5dd8894b958/core/libs/prx/libkernel/File/src/Stdio.cpp#L796-L811 - Test: https://github.com/boykopovar/AnyPS5/blob/d255b6d1840eb9bedadab87811964920d2b2bc1f/core/libs/tests/GuestJitSharedMemory.cpp ## Not verified - The guest test did not run hosted. - The Linux behaviour was not checked. ## To get this to a good state - Nothing to change. Running the guest test once on the hosted runner would confirm the new assertions.
MarcZX10 commented 2026-11-14 10:12:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T10:12:40Z.

Review: APPROVED


Reviewed — looks good

The inspected changes handle invalid guest pointers and descriptor cleanup coherently; the reported build and regression run were not independently reproduced.

What I ran

Reviewed head f86d7e4988c4d56a39df47af222fd0a0e8d03ec4 using the prepared diff and pinned reader. No build or test command was run. The PR description reports a Windows 11 x64 build and guest_jit_shared_memory passing; these are author-reported results.

Results

Check Result Note
Source review passed Changed code and relevant helpers inspected
Build and regression test not run PR description reports success
Console behavior not run Description says unmeasured

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read the full changed Jit.cpp and GuestJitSharedMemory.cpp, and the changed entry at the end of docs/dev/debt/libkernel.md. The prepared diff, description, commits, and manifest were read. The reported build and test were not rerun; console behavior was not measured.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903683140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14497#pullrequestreview-5903683140). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T10:12:40Z. **Review:** APPROVED --- # Reviewed — looks good The inspected changes handle invalid guest pointers and descriptor cleanup coherently; the reported build and regression run were not independently reproduced. ## What I ran Reviewed head `f86d7e4988c4d56a39df47af222fd0a0e8d03ec4` using the prepared diff and pinned reader. No build or test command was run. The PR description reports a Windows 11 x64 build and `guest_jit_shared_memory` passing; these are author-reported results. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed code and relevant helpers inspected | | Build and regression test | not run | PR description reports success | | Console behavior | not run | Description says unmeasured | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read the full changed `Jit.cpp` and `GuestJitSharedMemory.cpp`, and the changed entry at the end of `docs/dev/debt/libkernel.md`. The prepared diff, description, commits, and manifest were read. The reported build and test were not rerun; console behavior was not measured. ## To get this to a good state Nothing is required.
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!14497
No description provided.