fix(libSceHttp): copy guest outputs through GuestCopy #19769

Merged
gnavarro24 merged 9 commits from upstream-pr/19769 into main 2026-11-16 23:50:01 +00:00
gnavarro24 commented 2026-11-13 22:21:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gnavarro24 on 2026-11-13T22:21:57Z.


What

libSceHttp had 33 direct guest-pointer accesses across 22 exported functions. The scalar and struct outputs (memory pool stats, CA list, auth/cookie/gzip/nonblock enables, epoll handle, registered context ids, connection stats, cookie stats) were written straight through the guest pointer, so an unmapped output crashed the host instead of returning ERROR_INVALID_VALUE. Each value is now stored through GuestCopyOut_nid_no_patch via a small HttpGuest helper that preserves errno.

  • Export.cpp: sceHttpGetMemoryPoolStats, sceHttpsGetCaList, sceHttpsFreeCaList, sceHttpGetAuthEnabled, sceHttpGetCookieEnabled, sceHttpGetRegisteredCtxIds, sceHttpGetConnectionStat.
  • src/Options.cpp: sceHttpGetAutoRedirect, sceHttpGetNonblock, sceHttpGetAcceptEncodingGZIPEnabled, sceHttpGetEpoll.
  • src/Cookies.cpp: sceHttpGetCookieStats copies the whole struct in, sets its fields and copies it back, so the reserved word the console leaves alone is unchanged.

python3 tools/guest_pointer_audit.py libSceHttp goes from 33 direct accesses in 22 functions to 20 in 10.

Left out on purpose:

  • sceHttpGetLastErrno still writes its errno output in place. #9834, #11134 and #18515 rewrite its body, so it is left to them to avoid a conflict.
  • sceHttpGetCookie (needs a stored cookie, which the tests cannot create offline), sceHttpParseResponseHeader (returns pointers into the guest header, so its input cannot be copied in without changing its result), and the Uri.cpp and Client.cpp functions (overlap #12056 and #18346).

These are recorded in docs/dev/debt/libSceHttp.md.

Tested

Linux x86-64 (Ubuntu 24.04, GCC 13.3.0, Ninja, Release, -DBUILD_TESTING=ON), branch base main bab5bc6b98. A new guest_http_guest_pointers test (core/libs/tests/GuestHttpGuestPointers.cpp) passes; it calls each fixed export with an unmapped pointer (0x10) in place of the output and checks ERROR_INVALID_VALUE with errno preserved (set to 71 first), plus valid-pointer calls. The existing libSceHttp test binaries pass: guest_http, guest_http_options, guest_http_cookies, and all guest_http_state_* allocation modes (init, init-live, create, term 0-3).

Negative control: the original Export.cpp, src/Options.cpp and src/Cookies.cpp from main with the new test in place: guest_http_guest_pointer_tests exits 139 (SIGSEGV) in each of 3 runs.

python3 tools/check_conventions.py --base origin/main reports no errors; git diff --check is clean for the changed files. tools/pr_overlap.py could not confirm the overlap with #9834, #11134 and #18515 because they conflict with main. Compared by hand, their production changes touch sceHttpGetLastErrno (excluded here); their other hunks are test code and do not touch the functions changed here.

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:5303747186 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19769). Originally posted by [gnavarro24](https://github.com/gnavarro24) on 2026-11-13T22:21:57Z. --- ### What `libSceHttp` had 33 direct guest-pointer accesses across 22 exported functions. The scalar and struct outputs (memory pool stats, CA list, auth/cookie/gzip/nonblock enables, epoll handle, registered context ids, connection stats, cookie stats) were written straight through the guest pointer, so an unmapped output crashed the host instead of returning `ERROR_INVALID_VALUE`. Each value is now stored through `GuestCopyOut_nid_no_patch` via a small `HttpGuest` helper that preserves `errno`. - `Export.cpp`: `sceHttpGetMemoryPoolStats`, `sceHttpsGetCaList`, `sceHttpsFreeCaList`, `sceHttpGetAuthEnabled`, `sceHttpGetCookieEnabled`, `sceHttpGetRegisteredCtxIds`, `sceHttpGetConnectionStat`. - `src/Options.cpp`: `sceHttpGetAutoRedirect`, `sceHttpGetNonblock`, `sceHttpGetAcceptEncodingGZIPEnabled`, `sceHttpGetEpoll`. - `src/Cookies.cpp`: `sceHttpGetCookieStats` copies the whole struct in, sets its fields and copies it back, so the reserved word the console leaves alone is unchanged. `python3 tools/guest_pointer_audit.py libSceHttp` goes from 33 direct accesses in 22 functions to 20 in 10. **Left out on purpose:** - `sceHttpGetLastErrno` still writes its errno output in place. #9834, #11134 and #18515 rewrite its body, so it is left to them to avoid a conflict. - `sceHttpGetCookie` (needs a stored cookie, which the tests cannot create offline), `sceHttpParseResponseHeader` (returns pointers into the guest header, so its input cannot be copied in without changing its result), and the `Uri.cpp` and `Client.cpp` functions (overlap #12056 and #18346). These are recorded in `docs/dev/debt/libSceHttp.md`. ### Tested Linux x86-64 (Ubuntu 24.04, GCC 13.3.0, Ninja, Release, `-DBUILD_TESTING=ON`), branch base `main` `bab5bc6b98`. A new `guest_http_guest_pointers` test (`core/libs/tests/GuestHttpGuestPointers.cpp`) passes; it calls each fixed export with an unmapped pointer (`0x10`) in place of the output and checks `ERROR_INVALID_VALUE` with `errno` preserved (set to `71` first), plus valid-pointer calls. The existing libSceHttp test binaries pass: `guest_http`, `guest_http_options`, `guest_http_cookies`, and all `guest_http_state_*` allocation modes (`init`, `init-live`, `create`, `term 0-3`). Negative control: the original `Export.cpp`, `src/Options.cpp` and `src/Cookies.cpp` from `main` with the new test in place: `guest_http_guest_pointer_tests` exits 139 (SIGSEGV) in each of 3 runs. `python3 tools/check_conventions.py --base origin/main` reports no errors; `git diff --check` is clean for the changed files. `tools/pr_overlap.py` could not confirm the overlap with #9834, #11134 and #18515 because they conflict with `main`. Compared by hand, their production changes touch `sceHttpGetLastErrno` (excluded here); their other hunks are test code and do not touch the functions changed here. ### 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) - [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 03:34:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T03:34:37Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4820c34dd6:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_http_guest_pointer_tests built cleanly.
  • CTest (guest_http_guest_pointers):
    1/1 Test #3259: guest_http_guest_pointers ........   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceHttp/Export.cpp, core/libs/prx/libSceHttp/src/Cookies.cpp, core/libs/prx/libSceHttp/src/Options.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3259: guest_http_guest_pointers ........***Exception: SegFault  0.41 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceHttp/src/GuestAccess.hpp: verified CopyIn, CopyOut, and Store save and restore errno around GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch and preserve destination/source argument ordering.
    • core/libs/prx/libSceHttp/Export.cpp: verified sceHttpGetMemoryPoolStats, sceHttpsGetCaList, sceHttpsFreeCaList, sceHttpGetAuthEnabled, sceHttpGetCookieEnabled, sceHttpGetRegisteredCtxIds, and sceHttpGetConnectionStat return ERROR_INVALID_VALUE on failed guest output stores without leaking unhandled exceptions.
    • core/libs/prx/libSceHttp/src/Options.cpp: verified sceHttpGetAutoRedirect, sceHttpGetNonblock, sceHttpGetAcceptEncodingGZIPEnabled, and sceHttpGetEpoll safely write through HttpGuest::Store and return ERROR_INVALID_VALUE if epoll or argument pointers are invalid.
    • core/libs/prx/libSceHttp/src/Cookies.cpp: verified sceHttpGetCookieStats correctly preserves the reserved struct field via CopyIn before updating stats and writing back via CopyOut, returning ERROR_INVALID_VALUE on copy failure.
    • core/libs/tests/GuestHttpGuestPointers.cpp: verified comprehensive coverage of unmapped pointer error returns and errno preservation across all updated exports, accompanied by valid-pointer success checks.
    • AGENTS.md & docs/dev/debt/libSceHttp.md: verified zero disallowed comments in source code, correct debt logging for deliberately unmigrated functions, and strict adherence to repository architectural conventions.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901324180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19769#pullrequestreview-5901324180). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T03:34:37Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `4820c34dd6`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_http_guest_pointer_tests` built cleanly. - **CTest** (`guest_http_guest_pointers`): ``` 1/1 Test #3259: guest_http_guest_pointers ........ Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceHttp/Export.cpp`, `core/libs/prx/libSceHttp/src/Cookies.cpp`, `core/libs/prx/libSceHttp/src/Options.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #3259: guest_http_guest_pointers ........***Exception: SegFault 0.41 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libSceHttp/src/GuestAccess.hpp: verified CopyIn, CopyOut, and Store save and restore errno around GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch and preserve destination/source argument ordering. - core/libs/prx/libSceHttp/Export.cpp: verified sceHttpGetMemoryPoolStats, sceHttpsGetCaList, sceHttpsFreeCaList, sceHttpGetAuthEnabled, sceHttpGetCookieEnabled, sceHttpGetRegisteredCtxIds, and sceHttpGetConnectionStat return ERROR_INVALID_VALUE on failed guest output stores without leaking unhandled exceptions. - core/libs/prx/libSceHttp/src/Options.cpp: verified sceHttpGetAutoRedirect, sceHttpGetNonblock, sceHttpGetAcceptEncodingGZIPEnabled, and sceHttpGetEpoll safely write through HttpGuest::Store and return ERROR_INVALID_VALUE if epoll or argument pointers are invalid. - core/libs/prx/libSceHttp/src/Cookies.cpp: verified sceHttpGetCookieStats correctly preserves the reserved struct field via CopyIn before updating stats and writing back via CopyOut, returning ERROR_INVALID_VALUE on copy failure. - core/libs/tests/GuestHttpGuestPointers.cpp: verified comprehensive coverage of unmapped pointer error returns and errno preservation across all updated exports, accompanied by valid-pointer success checks. - AGENTS.md & docs/dev/debt/libSceHttp.md: verified zero disallowed comments in source code, correct debt logging for deliberately unmigrated functions, and strict adherence to repository architectural conventions. - 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!19769
No description provided.