feat(libSceLibreSsl): implement SSL_CTX_get_ex_data #15281

Merged
alvaroelpob merged 4 commits from upstream-pr/15281 into main 2026-11-14 10:57:34 +00:00
alvaroelpob commented 2026-11-02 22:37:45 +00:00 (Migrated from github.com)

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


What

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

As in LibreSSL 2.5.4 ssl_lib.c and CRYPTO_get_ex_data in ex_data.c, it reads the stack of internal->ex_data. It returns null without a stack, null for an index past or before it, and the stored pointer otherwise.

ex_data is at offset 248 of the 464-byte context internal state, measured by compiling the 2.5.4 release's ssl_locl.h. That compile also gives the quiet_shutdown offset (292) #10483 already uses; this splits #10483's padding around it.

The function is added to #10483's src/SslCtx.cpp and its test to GuestLibreSslSslCtx.cpp, so this builds on it. A null context 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_ctx test: null context and null internal state throw; no stack returns null; a two-slot stack returns both slots and null for 2 and INT_MIN; setting quiet_shutdown next to it does not disturb the read.
  • Full ctest -j16 on head e2becae94b: 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 103a84772f, 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. Full build and ctest -j16: 3795/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: #10483
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5128552031 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15281). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-11-02T22:37:45Z. --- ### What Implements `SSL_CTX_get_ex_data(const SSL_CTX*, 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` and `CRYPTO_get_ex_data` in [`ex_data.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/ex_data.c), it reads the stack of `internal->ex_data`. It returns null without a stack, null for an index past or before it, and the stored pointer otherwise. `ex_data` is at offset 248 of the 464-byte context internal state, measured by compiling the 2.5.4 release's `ssl_locl.h`. That compile also gives the `quiet_shutdown` offset (292) #10483 already uses; this splits #10483's padding around it. The function is added to #10483's `src/SslCtx.cpp` and its test to `GuestLibreSslSslCtx.cpp`, so this builds on it. A null context 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_ctx` test: null context and null internal state throw; no stack returns null; a two-slot stack returns both slots and null for 2 and `INT_MIN`; setting `quiet_shutdown` next to it does not disturb the read. - Full `ctest -j16` on head e2becae94b: 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 103a84772f, 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`. Full build and `ctest -j16`: 3795/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: #10483 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
BunnyFl commented 2026-11-04 00:37:50 +00:00 (Migrated from github.com)

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

Review: APPROVED


@alvaroelpob approved at 103a84772f. I only looked at the new SSL_CTX_get_ex_data; the code from #10483 is theirs to review.

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

  • guest_libressl_ssl_ctx 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_CTX_get_ex_data returning nullptr first, guest_libressl_ssl_ctx fails at line 115 (1 of 1).

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

dbe60: mov    $0xf8,%eax
dbe65: add    0x70(%rdi),%rax
dbe69: mov    %rax,%rdi
dbe6c: jmp    0x11030

That is internal at 0x70 and ex_data at +0xf8, your 112 and 248, and the same shared reader as SSL_get_ex_data.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761541851 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15281#pullrequestreview-5761541851). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T00:37:50Z. **Review:** APPROVED --- @alvaroelpob approved at `103a84772f`. I only looked at the new `SSL_CTX_get_ex_data`; the code from #10483 is theirs to review. **What I ran:** this head merged onto `main` (merge `cde3bb9c12`), Windows 11, WinLibs GCC, Release. - `guest_libressl_ssl_ctx` 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_CTX_get_ex_data` returning `nullptr` first, `guest_libressl_ssl_ctx` fails at line 115 (1 of 1). **Firmware:** this answers what the layout compile left open. In 13.42 `system/common/lib/libSceLibreSsl.sprx` (sha256 `57de57100cdeecdf8db74d6914b0c50ac9a9113fead232d03dce2df227cd9032`), `SSL_CTX_get_ex_data` (`jLew9e14VI8`) is, read from disassembly and not run: ``` dbe60: mov $0xf8,%eax dbe65: add 0x70(%rdi),%rax dbe69: mov %rax,%rdi dbe6c: jmp 0x11030 ``` That is `internal` at `0x70` and `ex_data` at `+0xf8`, your 112 and 248, and the same shared reader as `SSL_get_ex_data`. So the offsets you got from compiling LibreSSL 2.5.4 match the console module.
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!15281
No description provided.