Skip to content

feat(libSceLibreSsl3): implement BIO_up_ref - #12945

Open
EagleBearerYS wants to merge 3 commits into
boykopovar:mainfrom
EagleBearerYS:feat/libressl3-bio-up-ref-on-12754
Open

EagleBearerYS wants to merge 3 commits into
boykopovar:mainfrom
EagleBearerYS:feat/libressl3-bio-up-ref-on-12754

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

BIO_up_ref in libSceLibreSsl3 was a bare stub. It now does what LibreSSL 4.0.0 does (bio_lib.c L198-L202): it raises the BIO's references by one and returns 1 when the new count is above 1, as CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO) > 1 does.

Overlap: #12580 and #12582 (PrivacyOnion) append their retains and test cases after SSL_CTX_up_ref too, in src/Key.cpp and GuestLibreSsl3KeyReference.cpp. Whichever merges second keeps both and recounts the debt line, which already conflicts between #12754 and them. If one of them lands before #12754, #12754 is rebased, and this branch restacks on it.

Tested

  • guest_libressl3_key_reference gains a bio case. It sits with the CheckKey cases (EVP_PKEY, EC_KEY, SSL_CTX) in GuestLibreSsl3KeyReference.cpp, since BIO_up_ref sits with their retains in src/Key.cpp; feat(libSceLibreSsl3): implement the SSL, SSL_SESSION and X509 retains, the SSL_CTX version bounds, SSL_get_client_random and X509_get_version #12754's CheckRetain cases are in GuestLibreSsl3Ssl.cpp. It covers:

    • initial counts -2, 0, 1, 37 and INT32_MAX - 1, with the result;
    • 16 guard bytes on each side, and the rest of the struct unchanged;
    • 32 repeated retains;
    • 4 threads × 1,000 concurrent retains, ending at exactly 4,001.

    No case asserts a throw.

  • Red: with the body put back to main's NotImplemented_nid_no_patch (the signature kept), the bio case aborts with BIO_up_ref_nid_postfix not implemented. The other cases still pass.

  • Green, Linux (Ubuntu 24.04, GCC 13.3, Release, CI's flags):

    • ctest -R "libressl3|crypto_memcmp" --repeat until-fail:10: 5 tests, 10 of 10 each, 0 skipped;
    • ctest -R "libressl|crypto_memcmp" once: 34 tests, 34 passed, 0 skipped.
  • Checks: check_conventions.py and check_test_registration.py pass. MinGW-w64 -fsyntax-only -Wall -Wextra: no errors or warnings.

  • GitHub, ×10 on both runners (run 40895956237), compared against feat(libSceLibreSsl3): implement the SSL, SSL_SESSION and X509 retains, the SSL_CTX version bounds, SSL_get_client_random and X509_get_version #12754's head: guest_libressl3_key_reference passed 10 of 10 on Linux and on Windows, 0 skipped.

    • The libc and libkernel suites, run with APS5_SKIP_TIMING_TESTS=1, pass: 171 and 291 tests on Linux, 199 and 314 on Windows.
    • On the runners, the base's code doesn't build the new case, because its stub takes no parameters. The red above was taken with the real signature kept and only the body put back.

Checklist

PrivacyOnion and others added 3 commits October 28, 2026 22:17
…s, the SSL_CTX version bounds, SSL_get_client_random and X509_get_version

SSL_up_ref, SSL_SESSION_up_ref and X509_up_ref add one to the reference
count of a caller-owned object through the retain helper of EVP_PKEY_up_ref,
now shared in Reference.hpp, which SSL_CTX_up_ref also uses.
SSL_CTX_set_min_proto_version and SSL_CTX_set_max_proto_version clamp the
requested bound to the method range and convert DTLS versions; the SSL_CTX
fields they use extend LibreSsl3SslCtx in Key.hpp. SSL_get_client_random
copies up to 32 bytes of the SSL3 client random, and X509_get_version reads
cert_info->version with the ASN1_INTEGER_get rules, queueing its ASN.1
errors.

Behaviour and object layouts follow LibreSSL 4.0.0 (ce488b78e0bd): ssl_lib.c,
ssl_sess.c, ssl_versions.c, ssl_local.h, x_all.c, x509_set.c, x509_local.h
and a_int.c. No upstream source is copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BIO_up_ref adds one to the reference count of a caller-owned BIO through
the shared retain in Reference.hpp and returns 1 when the new count is
above 1, as CRYPTO_add(...) > 1 does. LibreSsl3Bio in Key.hpp is the
112-byte BIO with its counter at offset 80.

Behaviour and layout follow LibreSSL 4.0.0 (ce488b78e0bd): bio_lib.c
L198-L202 and bio_local.h. No upstream source is copied.
@github-actions

Copy link
Copy Markdown

Progress report (bb04a4f → 219770a)

📈 System libraries: 46.55% (+0.06%, +9 implemented functions)

✅ 9 implemented
Library Name
libSceLibreSsl3 BIO_up_ref_nid_postfix
libSceLibreSsl3 SSL_CTX_set_max_proto_version_nid_postfix
libSceLibreSsl3 SSL_CTX_set_min_proto_version_nid_postfix
libSceLibreSsl3 SSL_CTX_up_ref_nid_postfix
libSceLibreSsl3 SSL_SESSION_up_ref_nid_postfix
libSceLibreSsl3 SSL_get_client_random_nid_postfix
libSceLibreSsl3 SSL_up_ref_nid_postfix
libSceLibreSsl3 X509_get_version_nid_postfix
libSceLibreSsl3 X509_up_ref_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 5/87 (5.75%) 14/87 (16.09%) +10.34 pp

@EagleBearerYS
EagleBearerYS marked this pull request as ready for review October 29, 2026 15:44
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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
PR 13873 core/libs/prx/libSceLibreSsl3/src/X509.cpp

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 9535 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 9536 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 9571 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 9970 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
docs/dev/debt/libSceLibreSsl3.md
PR 10395 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
core/libs/prx/libSceLibreSsl3/include/Key.hpp
core/libs/prx/libSceLibreSsl3/src/Key.cpp
core/libs/tests/GuestLibreSsl3KeyReference.cpp
docs/dev/debt/libSceLibreSsl3.md
PR 10452 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10461 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10490 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10491 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10493 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10557 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10631 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 10960 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 11146 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
core/libs/prx/libSceLibreSsl3/include/Key.hpp
core/libs/prx/libSceLibreSsl3/src/Key.cpp
core/libs/tests/GuestLibreSsl3KeyReference.cpp
docs/dev/debt/libSceLibreSsl3.md
PR 12315 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 12928 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 13659 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 13662 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 13831 core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 13873 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
core/libs/prx/libSceLibreSsl3/src/X509.cpp
docs/dev/debt/libSceLibreSsl3.md

@JJenkx

JJenkx commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Windows run of this head (219770ad1e), merged onto main bb04a4f1ea (clean merge, local only). Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON, no Vulkan driver visible.

  • This PR: guest_libressl3_key_reference, guest_libressl3_ssl pass 3 of 3 (ctest --repeat until-fail:3).
  • Negative control: not possible. With this PR's source files (core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/include/Key.hpp, core/libs/prx/libSceLibreSsl3/include/Reference.hpp, core/libs/prx/libSceLibreSsl3/include/Ssl.hpp, core/libs/prx/libSceLibreSsl3/include/X509.hpp and 3 more) put back to main's version, and the ones it adds removed, the build fails against the rest of the PR, so there is no source-only control.

AI-assisted: yes (Claude Code).

@Lindamea1

Copy link
Copy Markdown
Contributor

@EagleBearerYS a heads-up, since this branch carries #12754's commits. #12754 conflicted with main after #12369, and #12578 was rebased for the same reason (now ced92ec4ed), so I've replayed #12754 on that head as 0ee29b8d1b. The commits this branch carries (00b24c75b4, 48bc460a1d) are therefore outdated.

To restack: git fetch https://github.com/boykopovar/AnyPS5 pull/12754/head, then git rebase --onto 0ee29b8d1b 48bc460a1d. In a local replay of your commit, only docs/dev/debt/libSceLibreSsl3.md conflicts. Keep the HEAD side, which has #12754's two entries and #12369's sections, and add your entry right after those two; the other side still has their old text. Line 5 merges by itself. #12754's code and tests are unchanged, including Retain_nid_no_patch in include/Reference.hpp; only its two debt entries changed, to state #12369's forwarding.

AI-assisted: yes (Claude Code).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants