fix(libSceHttp2): validate SSL setter handles #3535

Merged
sktharunbalaji13-cmd merged 3 commits from upstream-pr/3535 into main 2026-10-11 21:37:50 +00:00
sktharunbalaji13-cmd commented 2026-10-11 12:38:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-11T12:38:32Z.


What

sceHttp2SetMinSslVersion, sceHttp2SslEnableOption and sceHttp2SslDisableOption discarded their id and returned success for any value. They now validate id against a live-handle registry and return SCE_HTTP2_ERROR_INVALID_ID (0x817B1100) for a handle that was never allocated, was deleted, or belonged to a terminated context, following the prosper reference. Networking is still not implemented, so the TLS value remains ignored; only the handle is validated.

The context-only g_pools map is replaced by one typed registry. sceHttp2Init, sceHttp2CreateTemplate, sceHttp2CreateRequestWithURL and sceHttp2CreateCookieBox register their handles (kind, owner, and pool size for contexts). sceHttp2Term, sceHttp2DeleteTemplate and sceHttp2DeleteRequest invalidate them and release descendants transitively (a template owns its requests; a context owns its templates and cookie boxes). sceHttp2GetMemoryPoolStats reads the pool size from the registry and keeps the console's ERROR_NULL_POINTER return and zeroed output for an unknown context. The setters accept any live handle kind, because no per-kind restriction is measured; ids stay monotonic and are never reused.

docs/dev/TechnicalDebt.md (libSceHttp2 entry) is updated to record the validation and to mark what remains unverified: whether the console restricts the handle kind these setters accept, and how it treats an id from a previous init/term cycle.

Tested

Windows, MinGW-w64 GCC 15.2.0, Ninja, Release (-DBUILD_TESTING=ON):

  • cmake --build build --target guest_http2_tests — built.
  • ctest --test-dir build -R guest_http2 --output-on-failure — passed (1/1).

The regression coverage in core/libs/tests/GuestHttp2.cpp adds: all three setters reject 0, -1 and a large never-allocated id; all three accept live context, template, request and cookie-box ids; a deleted request id is rejected (and the second sceHttp2DeleteRequest returns the invalid-id error); a deleted template and its outstanding request are rejected; a terminated context and all of its descendants are rejected; a fresh context after termination is accepted. Existing memory-pool, cookie, send-error and async assertions are unchanged.

Not run on a PS5. Console behaviour (per-kind restrictions and previous-cycle ids) is unverified.

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 in TechnicalDebt — not applicable to this change
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source — not applicable
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819103362 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-11T12:38:32Z. --- ### What `sceHttp2SetMinSslVersion`, `sceHttp2SslEnableOption` and `sceHttp2SslDisableOption` discarded their `id` and returned success for any value. They now validate `id` against a live-handle registry and return `SCE_HTTP2_ERROR_INVALID_ID` (`0x817B1100`) for a handle that was never allocated, was deleted, or belonged to a terminated context, following the [prosper](https://github.com/mattias800/prosper) reference. Networking is still not implemented, so the TLS value remains ignored; only the handle is validated. The context-only `g_pools` map is replaced by one typed registry. `sceHttp2Init`, `sceHttp2CreateTemplate`, `sceHttp2CreateRequestWithURL` and `sceHttp2CreateCookieBox` register their handles (kind, owner, and pool size for contexts). `sceHttp2Term`, `sceHttp2DeleteTemplate` and `sceHttp2DeleteRequest` invalidate them and release descendants transitively (a template owns its requests; a context owns its templates and cookie boxes). `sceHttp2GetMemoryPoolStats` reads the pool size from the registry and keeps the console's `ERROR_NULL_POINTER` return and zeroed output for an unknown context. The setters accept any live handle kind, because no per-kind restriction is measured; ids stay monotonic and are never reused. `docs/dev/TechnicalDebt.md` (libSceHttp2 entry) is updated to record the validation and to mark what remains unverified: whether the console restricts the handle kind these setters accept, and how it treats an id from a previous init/term cycle. ### Tested Windows, MinGW-w64 GCC 15.2.0, Ninja, Release (`-DBUILD_TESTING=ON`): - `cmake --build build --target guest_http2_tests` — built. - `ctest --test-dir build -R guest_http2 --output-on-failure` — passed (1/1). The regression coverage in `core/libs/tests/GuestHttp2.cpp` adds: all three setters reject `0`, `-1` and a large never-allocated id; all three accept live context, template, request and cookie-box ids; a deleted request id is rejected (and the second `sceHttp2DeleteRequest` returns the invalid-id error); a deleted template and its outstanding request are rejected; a terminated context and all of its descendants are rejected; a fresh context after termination is accepted. Existing memory-pool, cookie, send-error and async assertions are unchanged. Not run on a PS5. Console behaviour (per-kind restrictions and previous-cycle ids) is unverified. ### 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) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) — not applicable to this change - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source — not applicable - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
sktharunbalaji13-cmd commented 2026-10-11 12:44:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-11T12:44:11Z.


Hi, I investigated the failing CI checks on PR #3535 (fix(libSceHttp2): validate SSL setter handles).

The macOS, Ubuntu, and Windows relinker jobs, along with the conventions job, are failing during actions/checkout cleanup—not during compilation or convention checking.

The common error is:

fatal: No url found for submodule path '3rdparty/imgui' in .gitmodules

At base commit 1e8fff68c8f6d3b67e38be584e15706a70c9d8bf, 3rdparty/imgui exists as a gitlink (mode 160000), but .gitmodules has no corresponding entry. My read-only investigation traces the addition to commit ddf6b8c98 (2026-10-11T11:08:03Z), an unrelated NpTrophy2 test commit. The same checkout failure also affects the base commit's own Build workflow (run 38138220808: linux, windows and all three relinker jobs fail).

The checkout step itself is not the cause: the relinker jobs use submodules: false, yet actions/checkout still runs git submodule foreach --recursive to strip credentials, and that errors when a gitlink has no .gitmodules URL.

PR #3535 does not touch the submodule or .gitmodules. Could a maintainer check whether the 3rdparty/imgui gitlink was accidental (most likely, given it rode along in an unrelated commit) and should be removed, or whether its missing submodule URL should be restored in .gitmodules? Once main is repaired, the affected workflows can be rerun.

The local Windows guest_http2_tests build and ctest -R guest_http2 passed. The CI relinker builds and conventions checker have not yet run successfully, so I am not claiming those checks passed.

Thanks!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109150521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535#issuecomment-6109150521). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-11T12:44:11Z. --- Hi, I investigated the failing CI checks on PR #3535 (`fix(libSceHttp2): validate SSL setter handles`). The macOS, Ubuntu, and Windows relinker jobs, along with the conventions job, are failing during `actions/checkout` cleanup—not during compilation or convention checking. The common error is: ``` fatal: No url found for submodule path '3rdparty/imgui' in .gitmodules ``` At base commit `1e8fff68c8f6d3b67e38be584e15706a70c9d8bf`, `3rdparty/imgui` exists as a gitlink (mode `160000`), but `.gitmodules` has no corresponding entry. My read-only investigation traces the addition to commit `ddf6b8c98` (2026-10-11T11:08:03Z), an unrelated NpTrophy2 test commit. The same checkout failure also affects the base commit's own Build workflow (run `38138220808`: `linux`, `windows` and all three `relinker` jobs fail). The checkout step itself is not the cause: the relinker jobs use `submodules: false`, yet `actions/checkout` still runs `git submodule foreach --recursive` to strip credentials, and that errors when a gitlink has no `.gitmodules` URL. PR #3535 does not touch the submodule or `.gitmodules`. Could a maintainer check whether the `3rdparty/imgui` gitlink was accidental (most likely, given it rode along in an unrelated commit) and should be removed, or whether its missing submodule URL should be restored in `.gitmodules`? Once `main` is repaired, the affected workflows can be rerun. The local Windows `guest_http2_tests` build and `ctest -R guest_http2` passed. The CI relinker builds and conventions checker have not yet run successfully, so I am not claiming those checks passed. Thanks!
MarcZX10 commented 2026-10-11 12:51:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:51:06Z.


I reviewed the handle lifecycle changes. One follow-up gap: DeleteRequest erases g_completions[req_id], but DeleteTemplate and Term recursively erase descendant request handles through ReleaseOwnedHandles without clearing completion queues for those requests. A request that completed asynchronously before its template/context is deleted can therefore retain stale queue state, and WaitAsync still looks up that id without checking the live-handle registry. Could the cascade return/collect the removed request ids and erase their completion entries too? A regression could send an async request, delete its template or terminate the context, then verify the completion is no longer consumable and the request has no retained state.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109207552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535#issuecomment-6109207552). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T12:51:06Z. --- I reviewed the handle lifecycle changes. One follow-up gap: `DeleteRequest` erases `g_completions[req_id]`, but `DeleteTemplate` and `Term` recursively erase descendant request handles through `ReleaseOwnedHandles` without clearing completion queues for those requests. A request that completed asynchronously before its template/context is deleted can therefore retain stale queue state, and `WaitAsync` still looks up that id without checking the live-handle registry. Could the cascade return/collect the removed request ids and erase their completion entries too? A regression could send an async request, delete its template or terminate the context, then verify the completion is no longer consumable and the request has no retained state.
sktharunbalaji13-cmd commented 2026-10-11 14:53:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-11T14:53:06Z.


@MarcZX100 thanks for the review — I addressed the gap in bf99430cc (follow-up on the same branch, not a new PR).

ReleaseOwnedHandles now returns every transitively removed handle id, and sceHttp2DeleteTemplate and sceHttp2Term erase the completion queue of each removed request in addition to the handle itself. sceHttp2DeleteRequest uses the same helper, so the cascade no longer leaves stale queue state.

To keep the state from coming back under a race, completion insertion now coordinates with deletion: CompleteAsync validates that the request is a live request while holding the handle lock and inserts the completion under it. A send that races a deletion therefore either returns SCE_HTTP2_ERROR_INVALID_ID without queuing, or is erased by the deletion — so no completion is re-created after a deletion returns. sceHttp2WaitAsync is deliberately unchanged: it consumes from the queue, which is what makes the erase (rather than a liveness check in the wait) the thing that makes a cascade-deleted request's completion unconsumable.

Regression coverage in core/libs/tests/GuestHttp2.cpp: a request is sent asynchronously, its completion is drained from the user event, then sceHttp2DeleteTemplate (and separately sceHttp2Term) removes the request. The test asserts the completion can no longer be consumed, a late send returns the invalid-id error without queuing a new completion, and the removed handles report the invalid-id error. Existing request deletion, send-error, cookie, WebSocket and async assertions are unchanged.

Two caveats worth being explicit about:

  • The console's exact behavior for a send on a dead request id is unverified (networking is unimplemented), so the invalid-id return follows the module's existing convention rather than a measured value.
  • A sceHttp2WaitAsync running concurrently with a deletion can still consume a completion that was queued before the handle was removed, because the wait consumes under the completion lock only. Once the deletion returns, no completion for the deleted request remains and none can be re-created. That concurrent window is a known limitation, not something this change claims to close.

Tested on Windows, MinGW-w64 GCC 15.2.0, Ninja, Release (-DBUILD_TESTING=ON): cmake --build build --target guest_http2_tests built, and ctest --test-dir build -R guest_http2 --output-on-failure passed (1/1). As a control, temporarily disabling the cascade erase makes the same test fail, and restoring it makes it pass. Not run on a PS5.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6110275026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535#issuecomment-6110275026). Originally posted by [sktharunbalaji13-cmd](https://github.com/sktharunbalaji13-cmd) on 2026-10-11T14:53:06Z. --- @MarcZX100 thanks for the review — I addressed the gap in `bf99430cc` (follow-up on the same branch, not a new PR). `ReleaseOwnedHandles` now returns every transitively removed handle id, and `sceHttp2DeleteTemplate` and `sceHttp2Term` erase the completion queue of each removed request in addition to the handle itself. `sceHttp2DeleteRequest` uses the same helper, so the cascade no longer leaves stale queue state. To keep the state from coming back under a race, completion insertion now coordinates with deletion: `CompleteAsync` validates that the request is a live request while holding the handle lock and inserts the completion under it. A send that races a deletion therefore either returns `SCE_HTTP2_ERROR_INVALID_ID` without queuing, or is erased by the deletion — so no completion is re-created after a deletion returns. `sceHttp2WaitAsync` is deliberately unchanged: it consumes from the queue, which is what makes the erase (rather than a liveness check in the wait) the thing that makes a cascade-deleted request's completion unconsumable. Regression coverage in `core/libs/tests/GuestHttp2.cpp`: a request is sent asynchronously, its completion is drained from the user event, then `sceHttp2DeleteTemplate` (and separately `sceHttp2Term`) removes the request. The test asserts the completion can no longer be consumed, a late send returns the invalid-id error without queuing a new completion, and the removed handles report the invalid-id error. Existing request deletion, send-error, cookie, WebSocket and async assertions are unchanged. Two caveats worth being explicit about: - The console's exact behavior for a send on a dead request id is unverified (networking is unimplemented), so the invalid-id return follows the module's existing convention rather than a measured value. - A `sceHttp2WaitAsync` running concurrently with a deletion can still consume a completion that was queued before the handle was removed, because the wait consumes under the completion lock only. Once the deletion returns, no completion for the deleted request remains and none can be re-created. That concurrent window is a known limitation, not something this change claims to close. Tested on Windows, MinGW-w64 GCC 15.2.0, Ninja, Release (`-DBUILD_TESTING=ON`): `cmake --build build --target guest_http2_tests` built, and `ctest --test-dir build -R guest_http2 --output-on-failure` passed (1/1). As a control, temporarily disabling the cascade erase makes the same test fail, and restoring it makes it pass. Not run on a PS5.
github-actions[bot] commented 2026-10-11 18:36:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T18:36:17Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3869 core/libs/prx/libSceHttp2/Export.cpp L9-10, L20-21, L279-280
#3925 core/libs/prx/libSceHttp2/Export.cpp L33-35, L37-42
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112328261 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535#issuecomment-6112328261). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T18:36:17Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #3869 | `core/libs/prx/libSceHttp2/Export.cpp` [L9-10](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libSceHttp2/Export.cpp#L9-L10), [L20-21](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libSceHttp2/Export.cpp#L20-L21), [L279-280](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libSceHttp2/Export.cpp#L279-L280) | | | | #3925 | `core/libs/prx/libSceHttp2/Export.cpp` [L33-35](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libSceHttp2/Export.cpp#L33-L35), [L37-42](https://github.com/boykopovar/AnyPS5/blob/41f013f664f6ec36a8111f2c6f9772b76e562288/core/libs/prx/libSceHttp2/Export.cpp#L37-L42) | | |
adriadam10 commented 2026-10-11 21:32:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:32:16Z.


Checked on Linux: build + guest_http2 pass, the test fails with Export.cpp reverted, and the invalid-id returns (setters, Term/Delete*/Create*, async send/wait) match prosper's hle_http2.cpp. The cascade now also clears the completion queues MarcZX100 pointed out.

Added one commit: the TechnicalDebt entry now also lists the other exports that return the invalid-id error for a stale or wrong-kind handle (prosper, not measured on a console). Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114006879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3535#issuecomment-6114006879). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:32:16Z. --- Checked on Linux: build + `guest_http2` pass, the test fails with `Export.cpp` reverted, and the invalid-id returns (setters, Term/Delete*/Create*, async send/wait) match prosper's `hle_http2.cpp`. The cascade now also clears the completion queues MarcZX100 pointed out. Added one commit: the TechnicalDebt entry now also lists the other exports that return the invalid-id error for a stale or wrong-kind handle (prosper, not measured on a console). Merging once CI is green.
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!3535
No description provided.