fix(libSceNKWebKitRequirements): guard psl_load_fp stream check with HostWrite #28267

Merged
NobleBrains merged 2 commits from upstream-pr/28267 into main 2026-12-03 17:23:26 +00:00
NobleBrains commented 2026-11-29 14:49:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-11-29T14:49:43Z.


What

core/libs/prx/libSceNKWebKitRequirements/Psl.cpp (psl_load_fp_nid_postfix) checked the guest stream via GuestWritable_nid_no_patch without an enclosing GuestArena::HostWrite guard.

  • Open GuestArena::HostWrite before the writability check and keep it while the stream is read and synced; return null when guard.Open() or the check fails.
  • Preserve host errno across the check.
  • Extend core/libs/prx/libSceNKWebKitRequirements/tests/Psl.cpp with HostWrite hook tests for an unmapped and a valid stream and errno preservation.

Tested

Linux (Distrobox build): ctest -R '^guest_nk_req_psl$' passed (1/1); python3 tools/check_conventions.py passed; python3 tools/pr_overlap.py --branch reported no overlap with open pull requests. Windows: not tested.

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
    • Improved handling of web content policy data when its input stream is unavailable or cannot be read, helping prevent invalid access.
    • Preserved error information when loading cannot proceed, and ensured successful loads retain their reported result.
    • Added coverage for valid, invalid, and missing input streams to verify the updated behavior.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5551853157 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-11-29T14:49:43Z. --- ### What `core/libs/prx/libSceNKWebKitRequirements/Psl.cpp` (`psl_load_fp_nid_postfix`) checked the guest stream via `GuestWritable_nid_no_patch` without an enclosing `GuestArena::HostWrite` guard. - Open `GuestArena::HostWrite` before the writability check and keep it while the stream is read and synced; return null when `guard.Open()` or the check fails. - Preserve host `errno` across the check. - Extend `core/libs/prx/libSceNKWebKitRequirements/tests/Psl.cpp` with `HostWrite` hook tests for an unmapped and a valid stream and `errno` preservation. ### Tested Linux (Distrobox build): `ctest -R '^guest_nk_req_psl$'` passed (`1/1`); `python3 tools/check_conventions.py` passed; `python3 tools/pr_overlap.py --branch` reported no overlap with open pull requests. Windows: not tested. ### 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** * Improved handling of web content policy data when its input stream is unavailable or cannot be read, helping prevent invalid access. * Preserved error information when loading cannot proceed, and ensured successful loads retain their reported result. * Added coverage for valid, invalid, and missing input streams to verify the updated behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-29 14:50:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T14:50:32Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_nk_req_psl_tests built cleanly.
  • CTest (guest_nk_req_psl):
    1/1 Test #5680: guest_nk_req_psl .................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKitRequirements/Psl.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5680: guest_nk_req_psl .................Subprocess aborted***Exception:   0.12 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified GuestArena::HostWrite RAII scoping and guard.Open() check around GuestWritable_nid_no_patch, psl_load_fp, and SyncFileStream in psl_load_fp_nid_postfix (core/libs/prx/libSceNKWebKitRequirements/Psl.cpp:176-184).
    • Verified host errno preservation across failed guard/writability checks as well as across successful psl_load_fp and SyncFileStream execution.
    • Verified nullptr handling for FileStream* fp before attempting guard construction or dereferencing.
    • Verified ScopedHostWriteHook RAII hook installation and cleanup in guest_nk_req_psl tests (core/libs/prx/libSceNKWebKitRequirements/tests/Psl.cpp:28-35).
    • Verified compliance with AGENTS.md rules regarding no illegal comments, no stub returns, and clean conventions gate pass.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6103383254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267#pullrequestreview-6103383254). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-29T14:50:32Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `53c4a2f520`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_nk_req_psl_tests` built cleanly. - **CTest** (`guest_nk_req_psl`): ``` 1/1 Test #5680: guest_nk_req_psl ................. Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKitRequirements/Psl.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5680: guest_nk_req_psl .................Subprocess aborted***Exception: 0.12 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified GuestArena::HostWrite RAII scoping and guard.Open() check around GuestWritable_nid_no_patch, psl_load_fp, and SyncFileStream in psl_load_fp_nid_postfix (core/libs/prx/libSceNKWebKitRequirements/Psl.cpp:176-184). - Verified host errno preservation across failed guard/writability checks as well as across successful psl_load_fp and SyncFileStream execution. - Verified nullptr handling for FileStream* fp before attempting guard construction or dereferencing. - Verified ScopedHostWriteHook RAII hook installation and cleanup in guest_nk_req_psl tests (core/libs/prx/libSceNKWebKitRequirements/tests/Psl.cpp:28-35). - Verified compliance with AGENTS.md rules regarding no illegal comments, no stub returns, and clean conventions gate pass. Looks Good To Me
MarcZX10 commented 2026-11-29 15:09:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T15:09:58Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 53c4a2f520aec0420a162b3c502d422d51d6f592 using repo_read.py to inspect the prepared diff and changed files, plus the relevant GuestArena and GuestWritable implementations. I did not run tests or other commands.

Results

Check Result Note
Changed code review passed Both changed files read
PR checks not run Linux results are author-reported
Negative control not run No test execution available

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

Tests were not run independently. The Linux ctest and convention-check results in the PR description are author-reported; Windows behavior was not tested. Both files listed under reviewed in manifest.json were read; no changed files were excluded.

To get this to a good state

Nothing is required. The PR description's test results are optional context and were not independently verified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6103457044 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267#pullrequestreview-6103457044). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-29T15:09:58Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Reviewed head `53c4a2f520aec0420a162b3c502d422d51d6f592` using `repo_read.py` to inspect the prepared diff and changed files, plus the relevant `GuestArena` and `GuestWritable` implementations. I did not run tests or other commands. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files read | | PR checks | not run | Linux results are author-reported | | Negative control | not run | No test execution available | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Changed `Psl.cpp` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/53c4a2f520aec0420a162b3c502d422d51d6f592/core/libs/prx/libSceNKWebKitRequirements/Psl.cpp#L170-L185) - [Changed `tests/Psl.cpp` at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/53c4a2f520aec0420a162b3c502d422d51d6f592/core/libs/prx/libSceNKWebKitRequirements/tests/Psl.cpp#L148-L171) - `GuestArena::HostWrite` and `GuestWritable_nid_no_patch` implementations were also read. ## Not verified Tests were not run independently. The Linux `ctest` and convention-check results in the PR description are author-reported; Windows behavior was not tested. Both files listed under `reviewed` in `manifest.json` were read; no changed files were excluded. ## To get this to a good state Nothing is required. The PR description's test results are optional context and were not independently verified.
MarcZX10 commented 2026-12-03 06:49:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T06:49:41Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at 045652dcd2c5d4909d470bb29c10cd8c0f8d8ac5 holds HostWrite across stream validation, loading, and synchronization, and I found no defect in the changed code.

What I ran

Reviewed the prepared diff and both changed files in full. Used repo_read.py at the pinned head to inspect HostWrite, GuestWritable_nid_no_patch, and GetNativeStream behavior. No tests or builds were run.

repo_read.py search 'GuestArenaBeginHostWrite_nid_postfix'
repo_read.py search 'bool GuestWritable_nid_no_patch'
repo_read.py cat core/libs/prx/libc/src/GuestArena.cpp 1035 1100
repo_read.py cat core/libs/prx/libc/src/General.cpp 945 985
repo_read.py cat core/libs/prx/libc/include/GuestArena.hpp 1 200
repo_read.py cat core/libs/prx/libc/include/FileStream.hpp 810 840

Results

Check Result Note
Changed code review passed Both changed files read in full
Tests and build not run Description reports Linux tests; not independently run
Windows behavior not run Not verified on Windows

Negative control

Not run; no tests were executed during this review.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

No tests or builds were run, and Windows behavior was not verified. Both changed files listed under reviewed were read in full; files.json lists no excluded files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6164950309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267#pullrequestreview-6164950309). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-03T06:49:41Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at `045652dcd2c5d4909d470bb29c10cd8c0f8d8ac5` holds `HostWrite` across stream validation, loading, and synchronization, and I found no defect in the changed code. ## What I ran Reviewed the prepared diff and both changed files in full. Used `repo_read.py` at the pinned head to inspect `HostWrite`, `GuestWritable_nid_no_patch`, and `GetNativeStream` behavior. No tests or builds were run. ```text repo_read.py search 'GuestArenaBeginHostWrite_nid_postfix' repo_read.py search 'bool GuestWritable_nid_no_patch' repo_read.py cat core/libs/prx/libc/src/GuestArena.cpp 1035 1100 repo_read.py cat core/libs/prx/libc/src/General.cpp 945 985 repo_read.py cat core/libs/prx/libc/include/GuestArena.hpp 1 200 repo_read.py cat core/libs/prx/libc/include/FileStream.hpp 810 840 ``` ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files read in full | | Tests and build | not run | Description reports Linux tests; not independently run | | Windows behavior | not run | Not verified on Windows | ## Negative control Not run; no tests were executed during this review. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Psl.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/045652dcd2c5d4909d470bb29c10cd8c0f8d8ac5/core/libs/prx/libSceNKWebKitRequirements/Psl.cpp#L170-L185) - [GuestArena.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/045652dcd2c5d4909d470bb29c10cd8c0f8d8ac5/core/libs/prx/libc/src/GuestArena.cpp#L1073-L1082) - [General.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/045652dcd2c5d4909d470bb29c10cd8c0f8d8ac5/core/libs/prx/libc/src/General.cpp#L960-L985) ## Not verified No tests or builds were run, and Windows behavior was not verified. Both changed files listed under `reviewed` were read in full; `files.json` lists no excluded files. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 08:10:38 +00:00 (Migrated from github.com)

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

Review: COMMENTED


I compiled the changed stream wrapper and its fixture against the project's pinned libpsl and Linux guest libraries. The test passed with the hook that changes errno on entry, preserving the caller's value for both the successfully parsed stream and the rejected stream. The accepted stream reached EOF and the fixture's four guest-path cases and nine source-selection cases also passed. This run exercised Linux.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165872903 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267#pullrequestreview-6165872903). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T08:10:38Z. **Review:** COMMENTED --- I compiled the changed stream wrapper and its fixture against the project's pinned libpsl and Linux guest libraries. The test passed with the hook that changes `errno` on entry, preserving the caller's value for both the successfully parsed stream and the rejected stream. The accepted stream reached EOF and the fixture's four guest-path cases and nine source-selection cases also passed. This run exercised Linux. AI-assisted: yes.
Plyxen commented 2026-12-03 15:51:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T15:51:45Z.

Review: APPROVED


I read the diff at 045652dcd2. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at c1593e4e1dd together with other open PRs (so not an isolated build).

  • guest_nk_req_psl: pass on both.
  • Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to main's): it fails with "unmapped psl_load_fp check should open HostWrite".

Not checked: a page that the GPU write watch really protects: the test counts the write brackets.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6173271748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28267#pullrequestreview-6173271748). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T15:51:45Z. **Review:** APPROVED --- I read the diff at `045652dcd2`. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into `main` at `c1593e4e1dd` together with other open PRs (so not an isolated build). - `guest_nk_req_psl`: pass on both. - Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to `main`'s): it fails with "unmapped psl_load_fp check should open HostWrite". Not checked: a page that the GPU write watch really protects: the test counts the write brackets. AI-assisted: yes (Claude Code)
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!28267
No description provided.