Skip to content

fix(libSceLibreSsl3): keep RSA_free from binding to its own export - #22877

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Herolias:fix/libressl3-rsa-free-self-import
Nov 18, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Herolias:fix/libressl3-rsa-free-self-import

Conversation

@Herolias

Copy link
Copy Markdown
Contributor

What

  • libSceLibreSsl3's RSA_free (RSA_free_nid_disambig1_nid_postfix in src/RsaCrypto.cpp, added in feat(libSceLibreSsl3): implement RSA_free and d2i_RSAPublicKey_bio #22804) hands a key whose method pointer is set to libSceLibreSsl's RSA_free_nid_postfix export. After NID patching that import is named 5zpup0URQoc, which libSceLibreSsl3 also exports as its own RSA_free. When libSceLibreSsl3 comes before libSceLibreSsl in the lookup scope, the import binds to libSceLibreSsl3's own export, which then calls itself forever. patched_self_imports has failed on Linux since feat(libSceLibreSsl3): implement RSA_free and d2i_RSAPublicKey_bio #22804 with libSceLibreSsl3.prx imports 5zpup0URQoc, a name it also exports, so the import can bind to its own export. The Windows job is the only one PR CI runs, so CI does not show it.
  • libSceLibreSsl now keeps the RSA_free body in LibreSslRsaFree_nid_no_patch, which its export and libSceLibreSsl3's RSA_free both call. This is the split 6c5bee0 (fix(prx): keep forwarding exports from binding to themselves on Linux #13730) made for the other forwarders. The declaration follows libSceLibreSsl's existing cross-library bodies such as LibreSslAsn1StringFree_nid_no_patch (extern "C", no APS5_VABI).
  • No behaviour changes. The body moves unchanged. Its null-method invalid_argument keeps the text RSA_free_nid_postfix: null method that __func__ produced before, as 6c5bee0 did for FT_Stroker_Export. libSceLibreSsl's own callers still call the export. No debt entry changes: feat(libSceLibreSsl3): implement RSA_free and d2i_RSAPublicKey_bio #22804's RSA_free entry ("A key whose method pointer is set goes to libSceLibreSsl's RSA_free") stays true.
  • feat(libSceLibreSsl3): implement RSA_free and d2i_RSAPublicKey_bio #22804 added no other call of this kind. RsaPublicKeyBio.cpp calls only libSceLibreSsl3's own RSA_new, RSA_free and BN_clear_free and libSceLibreSsl's LibreSslPutError_nid_no_patch body. patched_self_imports now passes over all 413 patched libraries.

Tested

Fedora Linux 44, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release build with -DBUILD_TESTING=ON, on main at 41bb4ae756. No title, no console and no Windows host.

  • The build passes, and patched_self_imports passes: "No patched library imports a name it exports (413 libraries)". In the patched modules, libSceLibreSsl defines 5zpup0URQoc and LibreSslRsaFree_nid_no_patch. libSceLibreSsl3 defines 5zpup0URQoc, imports LibreSslRsaFree_nid_no_patch, and no longer imports 5zpup0URQoc.
  • Negative controls and symbol comparison, run on the earlier base 85f73c1daf:
    • With main's copies of the three changed files and libs rebuilt, patched_self_imports fails with the single line quoted above.
    • With only main's RsaCrypto.cpp, it fails the same way.
    • With the change restored and the tree rebuilt, it passes.
    • nm -D against that main build: libSceLibreSsl gains one defined name, LibreSslRsaFree_nid_no_patch. libSceLibreSsl3 defines the same names as on main. Its only import changes are LibreSslRsaFree_nid_no_patch added and 5zpup0URQoc removed.
  • ctest -R 'libressl|^patched_self_imports$': 184 of 184 pass. Among them, guest_libressl3_rsa_public_key_bio's TestParentFree frees a libSceLibreSsl key through libSceLibreSsl3's RSA_free, which is the changed call. The guest tests load the unpatched libraries, so they cannot show the self-binding; patched_self_imports does.
  • On a local merge with main at 27beeee0a8, which adds feat(libSceLibreSsl3): implement d2i_RSA_PUBKEY #22845's d2i_RSA_PUBKEY, the build passes and the same 184 tests pass, patched_self_imports included.
  • tools/select_tests.py selects 1426 of 6123 tests for this change, and all 1426 pass.
  • x86_64-w64-mingw32-g++ 16.2.1 (Fedora MinGW) -fsyntax-only with -D_UCRT -D__MSVCRT_VERSION__=0xE00 passes for Rsa.cpp and RsaCrypto.cpp. Nothing ran on Windows.
  • python3 tools/check_conventions.py --base origin/main passes.
  • tools/pr_overlap.py --branch fails closed on fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466, feat(libSceLibreSsl): implement SSL_get0_param #15278, feat(libSceLibreSsl): implement SSL_get_ex_data #15279 and feat(libSceLibreSsl): implement SSL_get_servername #15280, which all conflict with main. I applied each one's hunks in the shared files (libSceLibreSsl Api.hpp, and Rsa.cpp for fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466) to main and to this branch, and the rejected hunks are identical, so this branch adds no conflict with them. fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466 shows RSA_free as a shared export because it re-adds the RSA_free that main already has.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

libSceLibreSsl3's RSA_free hands a key with a method pointer to
libSceLibreSsl's RSA_free export. After NID patching that import is named
5zpup0URQoc, which libSceLibreSsl3 also exports, so when libSceLibreSsl3
comes before libSceLibreSsl in the lookup scope the import binds to
libSceLibreSsl3's own RSA_free, which then calls itself forever.
patched_self_imports has failed on Linux since boykopovar#22804.

libSceLibreSsl now keeps the RSA_free body in LibreSslRsaFree_nid_no_patch,
which its export and libSceLibreSsl3's RSA_free call, as 6c5bee0 does for
the other forwarders. The body is unchanged, and its null-method message
keeps the export's name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the prx label Nov 18, 2026
@oneandonlydean
oneandonlydean merged commit 9a406d8 into boykopovar:main Nov 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants