fix(libSceNpUtility): validate full 0x18-byte async request parameter in NpLookup and NpWordFilter #27923

Merged
gurtgg merged 1 commit from upstream-pr/27923 into main 2026-12-04 07:03:19 +00:00
gurtgg commented 2026-11-27 20:31:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gurtgg on 2026-11-27T20:31:58Z.


What

  • Fixed sceNpLookupCreateAsyncRequest and sceNpWordFilterCreateAsyncRequest in core/libs/prx/libSceNpUtility/Export.cpp to validate the full 0x18-byte async request parameter (ASYNC_REQUEST_PARAMETER_SIZE) instead of reading only the leading 8-byte std::uint64_t size header.
  • Extracted shared helper CreateAsyncRequest using CopyInPreservingErrno so an async parameter struct crossing into unmapped/inaccessible guest memory returns SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT (0x80550704) while preserving errno.

Tested

  • CheckTruncatedAsyncParam (alongside CheckLookupAsync and CheckWordFilterAsync) in core/libs/tests/GuestNpUtilityOffline.cpp: places a valid uint64_t(0x18) size header in the last 8 bytes of a readable page immediately followed by a PAGE_NOACCESS/PROT_NONE guard page, verifying both sceNpLookupCreateAsyncRequest and sceNpWordFilterCreateAsyncRequest return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT (0x80550704) and preserve errno (fails on unmodified main, where both return a request id > 0).

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 upstream licence notices (tools/check_conventions.py passes)
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Negative-control regression test (plus valid/boundary cases) fails against unmodified main and passes after fix
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Lookup and word-filter asynchronous requests now handle invalid or incomplete parameters more safely, returning an invalid-argument error instead of attempting to process them.
    • Failed parameter validation no longer changes the system error state.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5532731742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27923). Originally posted by [gurtgg](https://github.com/gurtgg) on 2026-11-27T20:31:58Z. --- ### What - Fixed `sceNpLookupCreateAsyncRequest` and `sceNpWordFilterCreateAsyncRequest` in `core/libs/prx/libSceNpUtility/Export.cpp` to validate the full `0x18`-byte async request parameter (`ASYNC_REQUEST_PARAMETER_SIZE`) instead of reading only the leading 8-byte `std::uint64_t` size header. - Extracted shared helper `CreateAsyncRequest` using `CopyInPreservingErrno` so an async parameter struct crossing into unmapped/inaccessible guest memory returns `SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT` (`0x80550704`) while preserving `errno`. ### Tested - `CheckTruncatedAsyncParam` (alongside `CheckLookupAsync` and `CheckWordFilterAsync`) in `core/libs/tests/GuestNpUtilityOffline.cpp`: places a valid `uint64_t(0x18)` size header in the last 8 bytes of a readable page immediately followed by a `PAGE_NOACCESS`/`PROT_NONE` guard page, verifying both `sceNpLookupCreateAsyncRequest` and `sceNpWordFilterCreateAsyncRequest` return `SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT` (`0x80550704`) and preserve `errno` (fails on unmodified `main`, where both return a request id > 0). ### 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 and upstream licence notices (`tools/check_conventions.py` passes) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Negative-control regression test (plus valid/boundary cases) fails against unmodified `main` and passes after fix - [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** - Lookup and word-filter asynchronous requests now handle invalid or incomplete parameters more safely, returning an invalid-argument error instead of attempting to process them. - Failed parameter validation no longer changes the system error state. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-27 20:37:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-27T20:37:32Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_np_utility_offline_tests built cleanly.
  • CTest (guest_np_utility_offline):
    1/1 Test #5768: guest_np_utility_offline .........   Passed    0.16 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNpUtility/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5768: guest_np_utility_offline .........***Failed    0.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified CreateAsyncRequest in core/libs/prx/libSceNpUtility/Export.cpp checks param for nullptr before dereferencing, returning SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT (0x80550704).
    • Verified buffer size matches ASYNC_REQUEST_PARAMETER_SIZE (0x18 bytes) via static_assert and copies guest memory using CopyInPreservingErrno without corrupting errno on failure.
    • Verified buffer[0] is checked against ASYNC_REQUEST_PARAMETER_SIZE (0x18) to ensure size header matches the expected struct size.
    • Verified sceNpLookupCreateAsyncRequest and sceNpWordFilterCreateAsyncRequest both delegate to CreateAsyncRequest, resolving previous code duplication while retaining correct service references and titleCtxId forwarding.
    • Verified CheckTruncatedAsyncParam test in core/libs/tests/GuestNpUtilityOffline.cpp handles both Linux (mmap/mprotect/munmap) and Windows (VirtualAlloc/VirtualProtect/VirtualFree) correctly, validates preservation of errno, and cleans up contexts.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093135178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27923#pullrequestreview-6093135178). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-27T20:37:32Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `0781e6bd8c`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_np_utility_offline_tests` built cleanly. - **CTest** (`guest_np_utility_offline`): ``` 1/1 Test #5768: guest_np_utility_offline ......... Passed 0.16 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNpUtility/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5768: guest_np_utility_offline .........***Failed 0.13 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified CreateAsyncRequest in core/libs/prx/libSceNpUtility/Export.cpp checks param for nullptr before dereferencing, returning SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT (0x80550704). - Verified buffer size matches ASYNC_REQUEST_PARAMETER_SIZE (0x18 bytes) via static_assert and copies guest memory using CopyInPreservingErrno without corrupting errno on failure. - Verified buffer[0] is checked against ASYNC_REQUEST_PARAMETER_SIZE (0x18) to ensure size header matches the expected struct size. - Verified sceNpLookupCreateAsyncRequest and sceNpWordFilterCreateAsyncRequest both delegate to CreateAsyncRequest, resolving previous code duplication while retaining correct service references and titleCtxId forwarding. - Verified CheckTruncatedAsyncParam test in core/libs/tests/GuestNpUtilityOffline.cpp handles both Linux (mmap/mprotect/munmap) and Windows (VirtualAlloc/VirtualProtect/VirtualFree) correctly, validates preservation of errno, and cleans up contexts. Looks Good To Me
MarcZX10 commented 2026-11-27 20:47:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T20:47:35Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected implementation and regression test support merging.

What I ran

Reviewed head 0781e6bd8cfe32fc22862bb817cc9e3df7c340c4. No commands or tests were run; I inspected the prepared diff and the changed code through repo_read.py.

Results

Check Result Note
Changed code review passed Both async APIs share full-size validation
Regression test execution not run The guard-page test was inspected, not executed

Findings

Blocking

None.

Non-blocking

None.

Sources

Reviewed core/libs/prx/libSceNpUtility/Export.cpp and core/libs/tests/GuestNpUtilityOffline.cpp at the pinned head, including all changed lines. The implementation copies the complete 0x18-byte parameter with errno preservation and rejects inaccessible or incorrectly sized input. The added test covers a parameter ending at a guard page for both APIs and checks errno preservation.

Not verified

Tests, builds, and platform behavior were not run. The review bundle lists both changed files as reviewed, with full text included; no changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093211064 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27923#pullrequestreview-6093211064). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T20:47:35Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected implementation and regression test support merging. ## What I ran Reviewed head `0781e6bd8cfe32fc22862bb817cc9e3df7c340c4`. No commands or tests were run; I inspected the prepared diff and the changed code through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both async APIs share full-size validation | | Regression test execution | not run | The guard-page test was inspected, not executed | ## Findings ### Blocking None. ### Non-blocking None. ## Sources Reviewed `core/libs/prx/libSceNpUtility/Export.cpp` and `core/libs/tests/GuestNpUtilityOffline.cpp` at the pinned head, including all changed lines. The implementation copies the complete `0x18`-byte parameter with errno preservation and rejects inaccessible or incorrectly sized input. The added test covers a parameter ending at a guard page for both APIs and checks errno preservation. ## Not verified Tests, builds, and platform behavior were not run. The review bundle lists both changed files as reviewed, with full text included; no changed files were excluded. ## To get this to a good state Nothing is required.
Plyxen commented 2026-11-28 05:06:10 +00:00 (Migrated from github.com)

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

Review: APPROVED


Checked head 0781e6bd8c. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main a163d4b886 together with #27930, #27929, #27926, #27925, #27924, #27922, #27901, #27828, #27771, #27755, #27748, #27682, #27765. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. guest_np_utility_offline passes, including the new guard-page case through its VirtualProtect path. In the full CPU suite (5,120 tests) the only failures are unrelated:

  • windows_read_trap_unknown fails on main too (fixed in #28028).
  • frame_capture_minimize, jpeg_external_toolchain and guest_pthread_mutex_contention are timeouts under load; they pass when run on their own.
  • guest_audio_in_capture passes 20/20 on main and with #27922.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6095938586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27923#pullrequestreview-6095938586). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-11-28T05:06:10Z. **Review:** APPROVED --- Checked head `0781e6bd8c`. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to `main` `a163d4b886` together with #27930, #27929, #27926, #27925, #27924, #27922, #27901, #27828, #27771, #27755, #27748, #27682, #27765. `tools/check_conventions.py --head` and `tools/debt_fold.py --check` passed and the full build succeeded. `guest_np_utility_offline` passes, including the new guard-page case through its `VirtualProtect` path. In the full CPU suite (5,120 tests) the only failures are unrelated: - `windows_read_trap_unknown` fails on `main` too (fixed in #28028). - `frame_capture_minimize`, `jpeg_external_toolchain` and `guest_pthread_mutex_contention` are timeouts under load; they pass when run on their own. - `guest_audio_in_capture` passes 20/20 on `main` and with #27922. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 09:13:12 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The Linux GuestNpUtilityOffline fixture passed with the exact exports. Both lookup and word-filter async request paths exercise the short-parameter rejection, preserve errno, and clean up their test contexts.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6166731492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27923#pullrequestreview-6166731492). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T09:13:12Z. **Review:** COMMENTED --- The Linux `GuestNpUtilityOffline` fixture passed with the exact exports. Both lookup and word-filter async request paths exercise the short-parameter rejection, preserve errno, and clean up their test contexts. 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!27923
No description provided.