fix(libc): guard FloatingPrefix guest write checks with HostWrite #28246

Merged
NobleBrains merged 4 commits from upstream-pr/28246 into main 2026-12-03 17:22:48 +00:00
NobleBrains commented 2026-11-29 12:08:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NobleBrains on 2026-11-29T12:08:42Z.


What

core/libs/prx/libc/src/FloatingPrefix.cpp (ParsePrefix) checked the guest cursor and end pointers via GuestWritable_nid_no_patch without an enclosing GuestArena::HostWrite guard.

  • Open GuestArena::HostWrite before each writability check and fail when guard.Open() is false; host errno is still restored afterwards.
  • Check end only after the cursor check succeeded.
  • Extend core/libs/tests/GuestFloatingPrefix.cpp with HostWrite hook tests covering read-only cursor/end, valid outputs and errno preservation.

Tested

Linux (Distrobox build): ctest -R guest_floating_prefix passed (4/4, narrow/wide unpatched and patched); python3 tools/check_conventions.py passed; python3 tools/pr_overlap.py --branch reported 0 overlapping open PRs. 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 validation of output locations used by narrow and wide floating-point prefix parsing. Invalid locations are handled consistently without changing other output values, while valid parsing continues to preserve errno and return the expected results.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5550555339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246). Originally posted by [NobleBrains](https://github.com/NobleBrains) on 2026-11-29T12:08:42Z. --- ### What `core/libs/prx/libc/src/FloatingPrefix.cpp` (`ParsePrefix`) checked the guest `cursor` and `end` pointers via `GuestWritable_nid_no_patch` without an enclosing `GuestArena::HostWrite` guard. - Open `GuestArena::HostWrite` before each writability check and fail when `guard.Open()` is false; host `errno` is still restored afterwards. - Check `end` only after the `cursor` check succeeded. - Extend `core/libs/tests/GuestFloatingPrefix.cpp` with `HostWrite` hook tests covering read-only `cursor`/`end`, valid outputs and `errno` preservation. ### Tested Linux (Distrobox build): `ctest -R guest_floating_prefix` passed (`4/4`, narrow/wide unpatched and patched); `python3 tools/check_conventions.py` passed; `python3 tools/pr_overlap.py --branch` reported 0 overlapping open PRs. 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 validation of output locations used by narrow and wide floating-point prefix parsing. Invalid locations are handled consistently without changing other output values, while valid parsing continues to preserve `errno` and return the expected results. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-29 12:11:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T12:11:23Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 647a8a04c9:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_floating_prefix_tests built cleanly.
  • CTest (guest_floating_prefix_narrow, guest_floating_prefix_narrow_patched, guest_floating_prefix_wide, guest_floating_prefix_wide_patched):
    1/4 Test #7062: guest_floating_prefix_narrow_patched ...   Passed    0.97 sec
    2/4 Test #7061: guest_floating_prefix_narrow ...........   Passed    1.00 sec
    3/4 Test #7064: guest_floating_prefix_wide_patched .....   Passed    1.03 sec
    4/4 Test #7063: guest_floating_prefix_wide .............   Passed    1.11 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libc/src/FloatingPrefix.cpp reverted to main and the new tests kept, the suite fails:
    1/4 Test #7064: guest_floating_prefix_wide_patched .....***Failed    0.61 sec
    2/4 Test #7063: guest_floating_prefix_wide .............***Failed    0.67 sec
    3/4 Test #7062: guest_floating_prefix_narrow_patched ...***Failed    0.60 sec
    4/4 Test #7061: guest_floating_prefix_narrow ...........***Failed    0.65 sec
    0% tests passed, 4 tests failed out of 4
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ParsePrefix in core/libs/prx/libc/src/FloatingPrefix.cpp: GuestArena::HostWrite correctly guards cursor (const_cast<TChar**>(cursor), sizeof(*cursor)) and end (end, sizeof(*end)) before calling GuestWritable_nid_no_patch.
    • Verified short-circuiting and sequencing: cursor check precedes end check, and end guard is only evaluated if cursor check succeeds and end is non-null, matching expected parameter validation order.
    • Verified errno preservation: savedErrno is saved prior to GuestCopyIn / HostWrite checks and restored prior to evaluating validation results and before potential APS5_INVALID_ARG_EX throws.
    • Verified output copying in ParsePrefix: GuestCopyOut_nid_no_patch restores savedErrno on failure before APS5_INVALID_ARG_EX and succeeds with unchanged errno.
    • Verified test coverage in core/libs/tests/GuestFloatingPrefix.cpp: CheckHostWriteGuard thoroughly validates read-only cursor, read-only end, valid nan, and valid numeric cases on both Linux and Windows with ScopedHostWriteHook cleanup.
    • Verified AGENTS.md compliance: conventions, comments, and debt rules are followed; no comments introduced in source.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6102811234 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246#pullrequestreview-6102811234). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-29T12:11:23Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `647a8a04c9`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_floating_prefix_tests` built cleanly. - **CTest** (`guest_floating_prefix_narrow`, `guest_floating_prefix_narrow_patched`, `guest_floating_prefix_wide`, `guest_floating_prefix_wide_patched`): ``` 1/4 Test #7062: guest_floating_prefix_narrow_patched ... Passed 0.97 sec 2/4 Test #7061: guest_floating_prefix_narrow ........... Passed 1.00 sec 3/4 Test #7064: guest_floating_prefix_wide_patched ..... Passed 1.03 sec 4/4 Test #7063: guest_floating_prefix_wide ............. Passed 1.11 sec 100% tests passed, 0 tests failed out of 4 ``` - **Negative control**: with `core/libs/prx/libc/src/FloatingPrefix.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/4 Test #7064: guest_floating_prefix_wide_patched .....***Failed 0.61 sec 2/4 Test #7063: guest_floating_prefix_wide .............***Failed 0.67 sec 3/4 Test #7062: guest_floating_prefix_narrow_patched ...***Failed 0.60 sec 4/4 Test #7061: guest_floating_prefix_narrow ...........***Failed 0.65 sec 0% tests passed, 4 tests failed out of 4 ``` Restoring the change makes it pass again. - **Code reading**: - Verified ParsePrefix in core/libs/prx/libc/src/FloatingPrefix.cpp: GuestArena::HostWrite correctly guards cursor (const_cast<TChar**>(cursor), sizeof(*cursor)) and end (end, sizeof(*end)) before calling GuestWritable_nid_no_patch. - Verified short-circuiting and sequencing: cursor check precedes end check, and end guard is only evaluated if cursor check succeeds and end is non-null, matching expected parameter validation order. - Verified errno preservation: savedErrno is saved prior to GuestCopyIn / HostWrite checks and restored prior to evaluating validation results and before potential APS5_INVALID_ARG_EX throws. - Verified output copying in ParsePrefix: GuestCopyOut_nid_no_patch restores savedErrno on failure before APS5_INVALID_ARG_EX and succeeds with unchanged errno. - Verified test coverage in core/libs/tests/GuestFloatingPrefix.cpp: CheckHostWriteGuard thoroughly validates read-only cursor, read-only end, valid nan, and valid numeric cases on both Linux and Windows with ScopedHostWriteHook cleanup. - Verified AGENTS.md compliance: conventions, comments, and debt rules are followed; no comments introduced in source. Looks Good To Me
MarcZX10 commented 2026-11-29 12:26:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T12:26:59Z.

Review: COMMENTED


Reviewed — no blocking findings

The change appears sound from the code reviewed; the reported tests were not run here, so a formal approval is not justified.

What I ran

Reviewed head 647a8a04c9d1f19c64fcc9b615656a563f043ef8 using repo_read.py to inspect the prepared diff and changed files. No build or tests were run. The base is main; no merged-preview check was run.

Results

Check Result Note
Diff and changed code review passed Both changed files read
Reported Linux tests and conventions check not run Reported by the author
Windows tests not run Not tested

Negative control

Not run. No test change was made during this review.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

Builds and tests were not run. The Linux test and conventions results in the PR description are author-reported. Windows behavior is not verified. Both changed files listed in the manifest were read; no excluded files were identified there. The separate excluded-file inventory was unavailable.

To get this to a good state

Nothing is required. Optional: run the reported Linux checks and Windows tests when available.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6102864309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246#pullrequestreview-6102864309). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-29T12:26:59Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The change appears sound from the code reviewed; the reported tests were not run here, so a formal approval is not justified. ## What I ran Reviewed head `647a8a04c9d1f19c64fcc9b615656a563f043ef8` using `repo_read.py` to inspect the prepared diff and changed files. No build or tests were run. The base is `main`; no merged-preview check was run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Both changed files read | | Reported Linux tests and conventions check | not run | Reported by the author | | Windows tests | not run | Not tested | ## Negative control Not run. No test change was made during this review. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [FloatingPrefix.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/647a8a04c9d1f19c64fcc9b615656a563f043ef8/core/libs/prx/libc/src/FloatingPrefix.cpp) - [GuestFloatingPrefix.cpp at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/647a8a04c9d1f19c64fcc9b615656a563f043ef8/core/libs/tests/GuestFloatingPrefix.cpp) ## Not verified Builds and tests were not run. The Linux test and conventions results in the PR description are author-reported. Windows behavior is not verified. Both changed files listed in the manifest were read; no excluded files were identified there. The separate excluded-file inventory was unavailable. ## To get this to a good state Nothing is required. Optional: run the reported Linux checks and Windows tests when available.
MarcZX10 commented 2026-11-30 06:32:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:32:25Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the modified pointer checks are guarded with HostWrite, and the added tests cover read-only outputs and errno preservation.

What I ran

Reviewed head 6298404039a46b2cfaf0540f45862661539b86b0 using repo_read.py to inspect the prepared diff and targeted source context. No commands or tests were run by the reviewer.

Results

Check Result Note
Diff and changed source review passed Both changed files read
Reported Linux checks not run Reported by the author
Windows behavior not run Not tested per description

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports ctest -R guest_floating_prefix passed (4/4), python3 tools/check_conventions.py passed, and python3 tools/pr_overlap.py --branch found no overlapping open PRs; these were not run during this review. Windows behavior was not tested. Read: core/libs/prx/libc/src/FloatingPrefix.cpp, core/libs/tests/GuestFloatingPrefix.cpp, plus targeted context in core/libs/prx/libc/include/GuestArena.hpp, core/libs/prx/libc/src/General.cpp, and core/libs/prx/libc/src/GuestArena.cpp. No changed files were excluded; both files listed in the manifest were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6107796018 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246#pullrequestreview-6107796018). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-30T06:32:25Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the modified pointer checks are guarded with `HostWrite`, and the added tests cover read-only outputs and `errno` preservation. ## What I ran Reviewed head `6298404039a46b2cfaf0540f45862661539b86b0` using `repo_read.py` to inspect the prepared diff and targeted source context. No commands or tests were run by the reviewer. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source review | passed | Both changed files read | | Reported Linux checks | not run | Reported by the author | | Windows behavior | not run | Not tested per description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author reports `ctest -R guest_floating_prefix` passed (4/4), `python3 tools/check_conventions.py` passed, and `python3 tools/pr_overlap.py --branch` found no overlapping open PRs; these were not run during this review. Windows behavior was not tested. Read: `core/libs/prx/libc/src/FloatingPrefix.cpp`, `core/libs/tests/GuestFloatingPrefix.cpp`, plus targeted context in `core/libs/prx/libc/include/GuestArena.hpp`, `core/libs/prx/libc/src/General.cpp`, and `core/libs/prx/libc/src/GuestArena.cpp`. No changed files were excluded; both files listed in the manifest were read. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 06:43:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T06:43:15Z.

Review: COMMENTED


Ran all four floating-prefix CTests on Linux. The narrow and wide variants passed with both patched and unpatched libc, including the added guest write-watch output case.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6164861948 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246#pullrequestreview-6164861948). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T06:43:15Z. **Review:** COMMENTED --- Ran all four floating-prefix CTests on Linux. The narrow and wide variants passed with both patched and unpatched libc, including the added guest write-watch output case. AI-assisted: yes.
Plyxen commented 2026-12-03 15:51:38 +00:00 (Migrated from github.com)

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

Review: APPROVED


I read the diff at c9627469d6. 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).

  • the four guest_floating_prefix tests: 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): all four fail with "hostwrite readonly cursor hits".

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:6173269732 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28246#pullrequestreview-6173269732). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T15:51:38Z. **Review:** APPROVED --- I read the diff at `c9627469d6`. 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). - the four `guest_floating_prefix` tests: 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): all four fail with "hostwrite readonly cursor hits". 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!28246
No description provided.