feat(libSceLibreSsl): implement SSL_get_ex_data #15279

Closed
alvaroelpob wants to merge 7 commits from upstream-pr/15279 into main
alvaroelpob commented 2026-11-02 22:37:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-11-02T22:37:39Z.


What

Implements SSL_get_ex_data(const SSL*, int) in libSceLibreSsl, which threw and was declared without parameters.

As in LibreSSL 2.5.4 ssl_lib.c, it is CRYPTO_get_ex_data(&s->internal->ex_data, idx). ex_data.c returns null without a stack or for an index past it, and the sk_value already on main returns null for a negative one. This is the same code as main's X509_STORE_CTX_get_ex_data.

ex_data is at offset 272 of the 432-byte internal state, measured by compiling the 2.5.4 release's ssl_locl.h. That compile also gives the rwstate (156) and shutdown (168) offsets #10481 already uses; this splits #10481's padding around it.

Builds on the PRs below, which extend the same file and test. A null connection or internal state throws. The pending count drops by one.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON.

  • Extended guest_libressl_ssl test: null connection and null internal state throw; no stack returns null; a three-slot stack returns slot 0, the null slot 1 and slot 2; indexes 3 and -1 return null.
  • Full ctest -j16 on head 85322e1469: 3538/3538 pass. check_conventions.py --base upstream/main passes.
  • pr_overlap.py: no open pull request implements these functions. The shared lines are the pending-export count in docs/dev/debt/libSceLibreSsl.md and the lines its base PR also changes.
  • Not tested: Windows, a title.
  • Rebased on main 4f41f4c375, head 7a489bb527, to resolve the conflicts on the shared CMakeLists.txt, Export.cpp and debt-file lines; both sides are kept and the debt count is recomputed from Export.cpp. main now declares namespace LibreSsl in Bio.hpp, so the SSL struct is renamed LibreSslSsl in every commit; layout and static_asserts are unchanged. Full build and ctest -j16: 3796/3800 pass; guest_sce_net, guest_poll, guest_select_wait and guest_memory failed under that load, pass when run alone, and main 4f41f4c375 passes all 3799 with -j16 on the same machine. check_conventions.py --base upstream/main passes.

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: #10481, #15278
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5128550897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15279). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-02T22:37:39Z. --- ### What Implements `SSL_get_ex_data(const SSL*, int)` in libSceLibreSsl, which threw and was declared without parameters. As in [LibreSSL 2.5.4](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libssl/ssl_lib.c) `ssl_lib.c`, it is `CRYPTO_get_ex_data(&s->internal->ex_data, idx)`. [`ex_data.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/ex_data.c) returns null without a stack or for an index past it, and the `sk_value` already on `main` returns null for a negative one. This is the same code as `main`'s `X509_STORE_CTX_get_ex_data`. `ex_data` is at offset 272 of the 432-byte internal state, measured by compiling the 2.5.4 release's `ssl_locl.h`. That compile also gives the `rwstate` (156) and `shutdown` (168) offsets #10481 already uses; this splits #10481's padding around it. Builds on the PRs below, which extend the same file and test. A null connection or internal state throws. The pending count drops by one. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. - Extended `guest_libressl_ssl` test: null connection and null internal state throw; no stack returns null; a three-slot stack returns slot 0, the null slot 1 and slot 2; indexes 3 and -1 return null. - Full `ctest -j16` on head 85322e1469: 3538/3538 pass. `check_conventions.py --base upstream/main` passes. - `pr_overlap.py`: no open pull request implements these functions. The shared lines are the pending-export count in `docs/dev/debt/libSceLibreSsl.md` and the lines its base PR also changes. - Not tested: Windows, a title. - Rebased on `main` 4f41f4c375, head 7a489bb527, to resolve the conflicts on the shared `CMakeLists.txt`, `Export.cpp` and debt-file lines; both sides are kept and the debt count is recomputed from `Export.cpp`. `main` now declares `namespace LibreSsl` in `Bio.hpp`, so the SSL struct is renamed `LibreSslSsl` in every commit; layout and `static_assert`s are unchanged. Full build and `ctest -j16`: 3796/3800 pass; `guest_sce_net`, `guest_poll`, `guest_select_wait` and `guest_memory` failed under that load, pass when run alone, and `main` 4f41f4c375 passes all 3799 with `-j16` on the same machine. `check_conventions.py --base upstream/main` passes. ### 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: #10481, #15278 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-04 00:37:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T00:37:43Z.

Review: APPROVED


@alvaroelpob approved at 7a489bb527. I only looked at the new SSL_get_ex_data; the code from #10481 and #15278 is theirs to review.

What I ran: this head merged onto main (merge e358ef916d), Windows 11, WinLibs GCC, Release.

  • guest_libressl_ssl and public_headers pass (2 of 2). That covers the Windows run your description lists as not tested.
  • tools/check_conventions.py --base upstream/main --head on this head: all checks pass.
  • Mutation: with SSL_get_ex_data returning nullptr first, guest_libressl_ssl fails at line 161 (1 of 1).

Firmware: this answers what the layout compile left open. In 13.42 system/common/lib/libSceLibreSsl.sprx (sha256 57de57100cdeecdf8db74d6914b0c50ac9a9113fead232d03dce2df227cd9032), SSL_get_ex_data (QuI09j4a8-k) is, read from disassembly and not run:

dbe00: mov    $0x110,%eax
dbe05: add    0xe0(%rdi),%rax
dbe0c: mov    %rax,%rdi
dbe0f: jmp    0x11030

It takes internal at 0xe0 and ex_data at +0x110, then tail-calls the shared ex_data reader with the index still in esi. That is your internal at 224 and exData at 272.

So the offsets you got from compiling LibreSSL 2.5.4 match the console module.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761540971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15279#pullrequestreview-5761540971). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T00:37:43Z. **Review:** APPROVED --- @alvaroelpob approved at `7a489bb527`. I only looked at the new `SSL_get_ex_data`; the code from #10481 and #15278 is theirs to review. **What I ran:** this head merged onto `main` (merge `e358ef916d`), Windows 11, WinLibs GCC, Release. - `guest_libressl_ssl` and `public_headers` pass (2 of 2). That covers the Windows run your description lists as not tested. - `tools/check_conventions.py --base upstream/main --head` on this head: all checks pass. - **Mutation:** with `SSL_get_ex_data` returning `nullptr` first, `guest_libressl_ssl` fails at line 161 (1 of 1). **Firmware:** this answers what the layout compile left open. In 13.42 `system/common/lib/libSceLibreSsl.sprx` (sha256 `57de57100cdeecdf8db74d6914b0c50ac9a9113fead232d03dce2df227cd9032`), `SSL_get_ex_data` (`QuI09j4a8-k`) is, read from disassembly and not run: ``` dbe00: mov $0x110,%eax dbe05: add 0xe0(%rdi),%rax dbe0c: mov %rax,%rdi dbe0f: jmp 0x11030 ``` It takes `internal` at `0xe0` and `ex_data` at `+0x110`, then tail-calls the shared `ex_data` reader with the index still in `esi`. That is your `internal` at 224 and `exData` at 272. So the offsets you got from compiling LibreSSL 2.5.4 match the console module.
MarcZX10 commented 2026-11-20 21:21:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T21:21:13Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and its focused tests support merging, though the reported full test run on the rebased head had four failures under load.

What I ran

Reviewed head e19e1c3c42ee62f4f2732f67916fb8fbc58c85d2. No build or tests were run during this review; the test results below were reported in the PR description.

Results

Check Result Note
Code review passed Changed implementation and tests read
Build and tests not run PR reports 3796/3800 on rebased head
Conventions not run PR reports check passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not independently run the build, tests, or convention check. Did not verify behavior on Windows or a physical console. All five changed files listed in the manifest were read: core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/prx/libSceLibreSsl/include/Api.hpp, core/libs/prx/libSceLibreSsl/src/Ssl.cpp, core/libs/tests/GuestLibreSslSsl.cpp, and docs/dev/debt/libSceLibreSsl.md. The review-folder files.json was unavailable; no changed files were excluded according to the manifest.

To get this to a good state

Nothing is required. The reported load-sensitive failures are optional follow-up context; they are also reported to pass when run alone.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5999581570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15279#pullrequestreview-5999581570). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T21:21:13Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and its focused tests support merging, though the reported full test run on the rebased head had four failures under load. ## What I ran Reviewed head `e19e1c3c42ee62f4f2732f67916fb8fbc58c85d2`. No build or tests were run during this review; the test results below were reported in the PR description. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Changed implementation and tests read | | Build and tests | not run | PR reports 3796/3800 on rebased head | | Conventions | not run | PR reports check passed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not independently run the build, tests, or convention check. Did not verify behavior on Windows or a physical console. All five changed files listed in the manifest were read: `core/libs/prx/libSceLibreSsl/Export.cpp`, `core/libs/prx/libSceLibreSsl/include/Api.hpp`, `core/libs/prx/libSceLibreSsl/src/Ssl.cpp`, `core/libs/tests/GuestLibreSslSsl.cpp`, and `docs/dev/debt/libSceLibreSsl.md`. The review-folder `files.json` was unavailable; no changed files were excluded according to the manifest. ## To get this to a good state Nothing is required. The reported load-sensitive failures are optional follow-up context; they are also reported to pass when run alone.

Pull request closed

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!15279
No description provided.