fix(libSceSystemService): read guest title ID safely via GuestCopyIn #24962

Merged
nexus1692 merged 1 commit from upstream-pr/24962 into main 2026-11-24 15:21:23 +00:00
nexus1692 commented 2026-11-21 13:16:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nexus1692 on 2026-11-21T13:16:51Z.


What

sceSystemServiceGetAppId and sceLncUtilIsAppLaunched read their title ID with std::strlen and a std::string construction straight from the guest pointer (WellFormedTitleId). A non-null pointer that the process cannot read, or a string with no terminator within the 10-byte title ID buffer, therefore crashed the host instead of getting the documented answer. The other direction in the same file is already guarded: an unwritable title-ID buffer throws a host-safety rejection.

This replaces the helper with ReadTitleId, which reads one byte at a time through GuestCopyIn_nid_no_patch, stops at the terminator and never reads past TitleIdBufferSize, preserving the caller's errno. An unreadable pointer is answered as a malformed title ID: -1 from sceSystemServiceGetAppId and 0x80940005 from sceLncUtilIsAppLaunched. sceLncUtilIsAppLaunched still passes its own guest pointer on to sceSystemServiceGetAppId. The running-title answer, the -1 for a title ID whose length is not 9 and the throw for another title are unchanged, and no error code was added. Both are recorded in docs/dev/debt/libSceSystemService.md through the fragment.

docs/dev/debt/libSceSystemService.md already records the same class of fallback for the output buffer; the firmware reads the pointer unchecked and faults on it, which is not measured on a console.

Note: #14202 changes the rejection in RunningAppId on the same line, so one of the two needs a rebase.

Tested

Windows 11, x86-64 MinGW-w64 GCC 16.2.0, host-only change; no console run.

Check Result
ninja -k 0 -C build rc 0; libSceSystemService.prx patched and guest_system_service_app_title_id_tests.exe linked
ctest --test-dir build -R "app_title_id" --output-on-failure 3/3 passed (known, long, missing)
ctest --test-dir build -R "guest_system_service|lnc" --output-on-failure 30/30 passed
python tools/check_conventions.py --base origin/main all conventions checks passed
python tools/pr_overlap.py --names sceSystemServiceGetAppId,sceLncUtilGetAppId,sceLncUtilIsAppLaunched open: none
python tools/pr_overlap.py --branch fix/systemservice-title-id-guest-read no overlap with open pull requests

The new case passes an unreadable title ID (0x10) and requires -1 from both sceSystemServiceGetAppId and sceLncUtilGetAppId, 0x80940005 from sceLncUtilIsAppLaunched, and the caller's errno unchanged. The valid-title path (sceLncUtilIsAppLaunched with the running title) is covered by the existing checks, which still pass.

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 (FreeBuff). Replaces a raw title-ID read with a guarded guest read and adds the unreadable-pointer test.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5428188696 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24962). Originally posted by [nexus1692](https://github.com/nexus1692) on 2026-11-21T13:16:51Z. --- ### What `sceSystemServiceGetAppId` and `sceLncUtilIsAppLaunched` read their title ID with `std::strlen` and a `std::string` construction straight from the guest pointer (`WellFormedTitleId`). A non-null pointer that the process cannot read, or a string with no terminator within the 10-byte title ID buffer, therefore crashed the host instead of getting the documented answer. The other direction in the same file is already guarded: an unwritable title-ID buffer throws a host-safety rejection. This replaces the helper with `ReadTitleId`, which reads one byte at a time through `GuestCopyIn_nid_no_patch`, stops at the terminator and never reads past `TitleIdBufferSize`, preserving the caller's `errno`. An unreadable pointer is answered as a malformed title ID: `-1` from `sceSystemServiceGetAppId` and `0x80940005` from `sceLncUtilIsAppLaunched`. `sceLncUtilIsAppLaunched` still passes its own guest pointer on to `sceSystemServiceGetAppId`. The running-title answer, the `-1` for a title ID whose length is not 9 and the throw for another title are unchanged, and no error code was added. Both are recorded in `docs/dev/debt/libSceSystemService.md` through the fragment. `docs/dev/debt/libSceSystemService.md` already records the same class of fallback for the output buffer; the firmware reads the pointer unchecked and faults on it, which is not measured on a console. Note: #14202 changes the rejection in `RunningAppId` on the same line, so one of the two needs a rebase. ### Tested Windows 11, x86-64 MinGW-w64 GCC 16.2.0, host-only change; no console run. | Check | Result | | --- | --- | | `ninja -k 0 -C build` | rc 0; `libSceSystemService.prx` patched and `guest_system_service_app_title_id_tests.exe` linked | | `ctest --test-dir build -R "app_title_id" --output-on-failure` | 3/3 passed (known, long, missing) | | `ctest --test-dir build -R "guest_system_service\|lnc" --output-on-failure` | 30/30 passed | | `python tools/check_conventions.py --base origin/main` | all conventions checks passed | | `python tools/pr_overlap.py --names sceSystemServiceGetAppId,sceLncUtilGetAppId,sceLncUtilIsAppLaunched` | open: none | | `python tools/pr_overlap.py --branch fix/systemservice-title-id-guest-read` | no overlap with open pull requests | The new case passes an unreadable title ID (`0x10`) and requires `-1` from both `sceSystemServiceGetAppId` and `sceLncUtilGetAppId`, `0x80940005` from `sceLncUtilIsAppLaunched`, and the caller's `errno` unchanged. The valid-title path (`sceLncUtilIsAppLaunched` with the running title) is covered by the existing checks, which still pass. ### 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) 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 (FreeBuff). Replaces a raw title-ID read with a guarded guest read and adds the unreadable-pointer test.
MarcZX10 commented 2026-11-21 13:49:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T13:49:15Z.

Review: APPROVED


Reviewed — looks good

The changed title ID reads are bounded and use guarded guest copies; no blocking defect was found in the reviewed code.

What I ran

Reviewed head 712cae54768e9761c43190e92694096d3a36347d using repo_read.py to inspect the prepared diff, changed files, and targeted repository context. No build or tests were run; the checks in the PR description are author-reported.

Results

Check Result Note
Diff and changed behavior passed Three changed files reviewed
Build and tests not run Results in the description are author-reported
Console behavior not run No console run reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or build were run during this review. core/libs/prx/libSceSystemService/Export.cpp, core/libs/tests/GuestSystemServiceAppTitleId.cpp, and docs/dev/debt/changes/fix-systemservice-title-id-guest-read.md were read; all three changed files listed in the manifest were reviewed. Other repository files and physical console behavior were not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005649830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24962#pullrequestreview-6005649830). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T13:49:15Z. **Review:** APPROVED --- # Reviewed — looks good The changed title ID reads are bounded and use guarded guest copies; no blocking defect was found in the reviewed code. ## What I ran Reviewed head `712cae54768e9761c43190e92694096d3a36347d` using `repo_read.py` to inspect the prepared diff, changed files, and targeted repository context. No build or tests were run; the checks in the PR description are author-reported. ## Results | Check | Result | Note | | --- | --- | --- | | Diff and changed behavior | passed | Three changed files reviewed | | Build and tests | not run | Results in the description are author-reported | | Console behavior | not run | No console run reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or build were run during this review. `core/libs/prx/libSceSystemService/Export.cpp`, `core/libs/tests/GuestSystemServiceAppTitleId.cpp`, and `docs/dev/debt/changes/fix-systemservice-title-id-guest-read.md` were read; all three changed files listed in the manifest were reviewed. Other repository files and physical console behavior were not verified. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-21 14:09:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T14:09:59Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_system_service_app_title_id_tests built cleanly.
  • CTest (guest_system_service_app_title_id_known, guest_system_service_app_title_id_long, guest_system_service_app_title_id_missing):
    1/3 Test #5384: guest_system_service_app_title_id_long ......   Passed    0.09 sec
    2/3 Test #5383: guest_system_service_app_title_id_known .....   Passed    0.10 sec
    3/3 Test #5385: guest_system_service_app_title_id_missing ...   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libSceSystemService/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #5384: guest_system_service_app_title_id_long ......   Passed    0.11 sec
    2/3 Test #5385: guest_system_service_app_title_id_missing ...   Passed    0.03 sec
    3/3 Test #5383: guest_system_service_app_title_id_known .....***Exception: SegFault  0.68 sec
    67% tests passed, 1 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ReadTitleId in Export.cpp safely reads guest memory using GuestCopyIn_nid_no_patch up to TitleIdBufferSize (10 bytes), preventing out-of-bounds reads and preserving errno.
    • Verified null pointer handling and unreadable guest pointer handling in RunningAppId and sceLncUtilIsAppLaunched return SYSTEM_SERVICE_INVALID_TITLE_APP_ID (-1) and LNC_UTIL_ERROR_INVALID_ARGUMENT (0x80940005) respectively.
    • Verified string null-termination check and length validation against SYSTEM_SERVICE_TITLE_ID_LENGTH (9 chars) are correctly enforced before returning success.
    • Verified AGENTS.md compliance: no comments added, technical debt fragment added under docs/dev/debt/changes/, and no unauthorized files or silent stubs introduced.
    • Verified unit test additions in GuestSystemServiceAppTitleId.cpp properly exercise unreadable pointer handling and errno preservation.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005827415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24962#pullrequestreview-6005827415). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T14:09:59Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `712cae5476`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_system_service_app_title_id_tests` built cleanly. - **CTest** (`guest_system_service_app_title_id_known`, `guest_system_service_app_title_id_long`, `guest_system_service_app_title_id_missing`): ``` 1/3 Test #5384: guest_system_service_app_title_id_long ...... Passed 0.09 sec 2/3 Test #5383: guest_system_service_app_title_id_known ..... Passed 0.10 sec 3/3 Test #5385: guest_system_service_app_title_id_missing ... Passed 0.04 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libSceSystemService/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #5384: guest_system_service_app_title_id_long ...... Passed 0.11 sec 2/3 Test #5385: guest_system_service_app_title_id_missing ... Passed 0.03 sec 3/3 Test #5383: guest_system_service_app_title_id_known .....***Exception: SegFault 0.68 sec 67% tests passed, 1 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - Verified ReadTitleId in Export.cpp safely reads guest memory using GuestCopyIn_nid_no_patch up to TitleIdBufferSize (10 bytes), preventing out-of-bounds reads and preserving errno. - Verified null pointer handling and unreadable guest pointer handling in RunningAppId and sceLncUtilIsAppLaunched return SYSTEM_SERVICE_INVALID_TITLE_APP_ID (-1) and LNC_UTIL_ERROR_INVALID_ARGUMENT (0x80940005) respectively. - Verified string null-termination check and length validation against SYSTEM_SERVICE_TITLE_ID_LENGTH (9 chars) are correctly enforced before returning success. - Verified AGENTS.md compliance: no comments added, technical debt fragment added under docs/dev/debt/changes/, and no unauthorized files or silent stubs introduced. - Verified unit test additions in GuestSystemServiceAppTitleId.cpp properly exercise unreadable pointer handling and errno preservation. 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!24962
No description provided.