fix(libSceFiber): safely probe resume and return output pointers #19856

Merged
pushkarreddyy merged 3 commits from upstream-pr/19856 into main 2026-11-14 10:50:47 +00:00
pushkarreddyy commented 2026-11-14 03:50:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-11-14T03:50:12Z.


What

Probes and copies out arg_on_return in RunFiber and sceFiberReturnToThread, and arg_on_run_out in SwitchFiber, returning SCE_FIBER_ERROR_INVALID when guest memory cannot be written. Also reuses CopyGuestOut in sceFiberGetSelf to deduplicate pointer validation.

Tested

Windows 11, unit test RunUnwritablePointerCheck in core/libs/tests/Fiber.cpp verifying rejection of unwritable output pointers with errno == 71 preservation, and check_conventions.py passing with 0 findings.

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:5306905384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19856). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-14T03:50:12Z. --- ### What Probes and copies out `arg_on_return` in `RunFiber` and `sceFiberReturnToThread`, and `arg_on_run_out` in `SwitchFiber`, returning `SCE_FIBER_ERROR_INVALID` when guest memory cannot be written. Also reuses `CopyGuestOut` in `sceFiberGetSelf` to deduplicate pointer validation. ### Tested Windows 11, unit test `RunUnwritablePointerCheck` in `core/libs/tests/Fiber.cpp` verifying rejection of unwritable output pointers with `errno == 71` preservation, and `check_conventions.py` passing with 0 findings. ### Checklist - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-14 05:28:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T05:28:30Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: fiber_tests built cleanly.
  • CTest (fiber, fiber_contextless):
    1/2 Test #3147: fiber ............................   Passed    0.01 sec
    2/2 Test #3148: fiber_contextless ................   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceFiber/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #3148: fiber_contextless ................   Passed    0.02 sec
    2/2 Test #3147: fiber ............................***Exception: SegFault  0.22 sec
    50% tests passed, 1 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceFiber/Export.cpp:RunFiber: Verified that arg_on_return is guarded for nullptr and safely copied out via CopyGuestOut, returning SCE_FIBER_ERROR_INVALID on unwritable guest memory without altering errno.
    • core/libs/prx/libSceFiber/Export.cpp:SwitchFiber: Verified that arg_on_run_out permits nullptr and safely probes unwritable memory via CopyGuestOut, leaving the target fiber in a valid Suspended state on error.
    • core/libs/prx/libSceFiber/Export.cpp:sceFiberReturnToThread: Verified that arg_on_run permits nullptr and safely copies out the resumed transfer argument via CopyGuestOut, returning SCE_FIBER_ERROR_INVALID when unwritable.
    • core/libs/prx/libSceFiber/Export.cpp:sceFiberGetSelf: Verified that deduplicating the write through CopyGuestOut preserves the expected SCE_FIBER_ERROR_NULL return code and errno.
    • core/libs/tests/Fiber.cpp:RunUnwritablePointerCheck: Verified that the new unit test thoroughly exercises rejection of unwritable pointers for run, switch, and return paths, verifies errno preservation, resumes successfully, and cleanly finalizes all test fibers.
    • docs/dev/debt/libSceFiber.md: Verified that the defensive fallback behavior for unwritable argument pointers across all affected exports is documented under Functional debt with valid relative links.
    • AGENTS.md compliance: Verified zero forbidden comments in modified source/test files, no undocumented silent stubs, and conventional commit naming.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901893395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19856#pullrequestreview-5901893395). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T05:28:30Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `59720f36ef`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `fiber_tests` built cleanly. - **CTest** (`fiber`, `fiber_contextless`): ``` 1/2 Test #3147: fiber ............................ Passed 0.01 sec 2/2 Test #3148: fiber_contextless ................ Passed 0.02 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceFiber/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #3148: fiber_contextless ................ Passed 0.02 sec 2/2 Test #3147: fiber ............................***Exception: SegFault 0.22 sec 50% tests passed, 1 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libSceFiber/Export.cpp:RunFiber: Verified that arg_on_return is guarded for nullptr and safely copied out via CopyGuestOut, returning SCE_FIBER_ERROR_INVALID on unwritable guest memory without altering errno. - core/libs/prx/libSceFiber/Export.cpp:SwitchFiber: Verified that arg_on_run_out permits nullptr and safely probes unwritable memory via CopyGuestOut, leaving the target fiber in a valid Suspended state on error. - core/libs/prx/libSceFiber/Export.cpp:sceFiberReturnToThread: Verified that arg_on_run permits nullptr and safely copies out the resumed transfer argument via CopyGuestOut, returning SCE_FIBER_ERROR_INVALID when unwritable. - core/libs/prx/libSceFiber/Export.cpp:sceFiberGetSelf: Verified that deduplicating the write through CopyGuestOut preserves the expected SCE_FIBER_ERROR_NULL return code and errno. - core/libs/tests/Fiber.cpp:RunUnwritablePointerCheck: Verified that the new unit test thoroughly exercises rejection of unwritable pointers for run, switch, and return paths, verifies errno preservation, resumes successfully, and cleanly finalizes all test fibers. - docs/dev/debt/libSceFiber.md: Verified that the defensive fallback behavior for unwritable argument pointers across all affected exports is documented under Functional debt with valid relative links. - AGENTS.md compliance: Verified zero forbidden comments in modified source/test files, no undocumented silent stubs, and conventional commit naming. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!19856
No description provided.