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

Merged
Herolias merged 1 commit from upstream-pr/22877 into main 2026-11-18 13:59:54 +00:00
Herolias commented 2026-11-18 13:21:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Herolias on 2026-11-18T13:21:37Z.


What

  • libSceLibreSsl3's RSA_free (RSA_free_nid_disambig1_nid_postfix in src/RsaCrypto.cpp, added in #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 #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 6c5bee0282 (#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 6c5bee0282 did for FT_Stroker_Export. libSceLibreSsl's own callers still call the export. No debt entry changes: #22804's RSA_free entry ("A key whose method pointer is set goes to libSceLibreSsl's RSA_free") stays true.
  • #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 #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 #11466, #15278, #15279 and #15280, which all conflict with main. I applied each one's hunks in the shared files (libSceLibreSsl Api.hpp, and Rsa.cpp for #11466) to main and to this branch, and the rejected hunks are identical, so this branch adds no conflict with them. #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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5376787167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22877). Originally posted by [Herolias](https://github.com/Herolias) on 2026-11-18T13:21:37Z. --- ### What - libSceLibreSsl3's `RSA_free` (`RSA_free_nid_disambig1_nid_postfix` in `src/RsaCrypto.cpp`, added in #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 #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 6c5bee0282 (#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 6c5bee0282 did for `FT_Stroker_Export`. libSceLibreSsl's own callers still call the export. No debt entry changes: #22804's `RSA_free` entry ("A key whose method pointer is set goes to libSceLibreSsl's `RSA_free`") stays true. - #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 <!-- 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. --> 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 #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 #11466, #15278, #15279 and #15280, which all conflict with `main`. I applied each one's hunks in the shared files (libSceLibreSsl `Api.hpp`, and `Rsa.cpp` for #11466) to `main` and to this branch, and the rejected hunks are identical, so this branch adds no conflict with them. #11466 shows `RSA_free` as a shared export because it re-adds the `RSA_free` that `main` already has. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!22877
No description provided.