feat(libSceLibreSsl): implement the CRYPTO locking and thread id callbacks #10248
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10248"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mantavisual on 2026-10-23T15:31:41Z.
What
Implements five
libSceLibreSslexports that threw:CRYPTO_num_locks,CRYPTO_set_locking_callback,CRYPTO_set_add_lock_callback,CRYPTO_THREADID_set_callbackandCRYPTO_THREADID_set_numeric. They are the thread setup calls an OpenSSL 1.0-style application makes before anything else.Signatures and results follow LibreSSL 2.5.4's
cryptlib.candcrypto.h, the version identified in the firmware 13.40 measurements thatX509_verify_cert_error_stringalready cites:CRYPTO_num_locksreturnsCRYPTO_NUM_LOCKS, 41.CRYPTO_set_locking_callbackandCRYPTO_set_add_lock_callbackstore the callback (2.5.4'sOPENSSL_init()call there is empty).CRYPTO_THREADID_set_callbackreturns 0 when a callback is already set, otherwise stores it and returns 1, so a null callback while none is set returns 1 and leaves the slot empty. The first-set check is a compare-exchange.CRYPTO_THREADID_set_numericclears the 16-byte{void* ptr; unsigned long val}structure and stores the value. The value is a 64-bit integer here becauseunsigned longis 32 bits on Windows hosts. A null structure throws (APS5_INVALID_ARG_EX), since 2.5.4 writes through it unchecked.The callbacks are stored and never called. In 2.5.4 they are called from
CRYPTO_lock,CRYPTO_add_lockandCRYPTO_THREADID_current, around LibreSSL's own shared state. The PS5 3.20 export table lists none of those or any getter (itsCRYPTO_exports are these five plusCRYPTO_malloc,CRYPTO_free,CRYPTO_set_mem_functionsandCRYPTO_cleanup_all_ex_data), so the stored callbacks are observable only throughCRYPTO_THREADID_set_callback's result. This library's shared state uses host locking. The debt entry records this, along with the fact that nothing is checked on a console.CRYPTO_cleanup_all_ex_datais left throwing because no ex_data is implemented yet.The five declarations in
include/Api.hppnow carry these signatures, and the header holds the publicCryptoThreadIdlayout. The pending-export count indocs/dev/debt/libSceLibreSsl.mdgoes from 340 to 335:Export.cpphas 340 unknown-signature stubs onmain5bdda3661e(including the fivesceLibreSsl*exports) and 335 after this change.Tested
Windows 11 Pro 23H2, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, withmain5bdda3661emerged in (ad31835a6e). The merge only resolved the test registrations next to the new alert and version tests, tookmain's digest debt wording, and updated the pending count.New
guest_libressl_crypto_locks:CRYPTO_num_locksreturns 41. The locking and add-lock setters accept a function and null.CRYPTO_THREADID_set_callbackreturns 1 twice for null, 1 for the first function, then 0 for another function, the same function and null.CRYPTO_THREADID_set_numericclears a0xaa-filled structure to{nullptr, 0x1234567890abcdef}and a0x55-filled one to all zero bytes, and throws for a null structure. Onmaineach of these calls throws throughNotImplemented_nid_no_patch.ctest -R "guest_libressl|patched_libraries|^public_headers$": 16 of 16 pass (public_headers,patched_libraries,guest_libressl_x509_errors,guest_libressl_digest,guest_libressl_asn1,guest_libressl_asn1_allocator,guest_libressl_des,guest_libressl_runtime,guest_libressl_aes,guest_libressl_error,guest_libressl_ocsp,guest_libressl_cipher,guest_libressl_alert,guest_libressl_version,guest_libressl_crypto_locks,guest_libressl3_digest).The full build and the
libstarget complete.tools/check_test_registration.py build: 1397 test executables, none built and not run.Firmware: BunnyFl ran firmware 13.42's
libSceLibreSsl.sprxin an emulator and it matches all five: 41 locks, the 16-byte{ptr, val}write, first-set-wins for the thread id callback, and setters that only store.python3 tools/check_conventions.py --base origin/mainpasses. Overlap: no other open PR changes or names these five exports (checked 2026-10-25). #9529, whose error queue does not use a thread id callback, has merged; this branch keeps its test registration.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T20:02:48Z.
Review: DISMISSED
The implementation changes five distinct LibreSSL exports and the code/test diff is internally consistent with the cited 2.5.4 source. There is a merge blocker: this PR says
Depends on: noneand GitHub currently reportsDIRTY. A pairwise merge check against the open #9529 (git merge-tree --write-tree upstream/pr/9529 upstream/pr/10248) also has content conflicts incore/libs/prx/libSceLibreSsl/CMakeLists.txtanddocs/dev/debt/libSceLibreSsl.md. Please coordinate the landing order with the overlapping PR authors, declare required prerequisites in the template, rebase/resolve against current main, and verify all test registrations and the pending-export count are retained. Current conventions, intake, labels and report checks pass; product/relinker jobs are skipped by path policy. I did not run the tests locally.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T18:57:56Z.
Review: APPROVED
Reviewed head
c15dce4, merged locally onto maina7a2eec(base when I started). Ubuntu 24.04 on WSL2, GCC 13.3, Release.What I ran:
ctest -R "^(patched_libraries|guest_libressl)": 12/12 pass, includingguest_libressl_crypto_locks.NotImplemented_nid_no_patch(same signatures). The new test aborts on the first call,CRYPTO_num_locks_nid_postfix not implemented.libcrypto.a: the same call sequence through the PR's exports and through 2.5.4, with the output diffed. 38 lines each, no differences. It coveredsizeof/offsetofofCRYPTO_THREADID(16, ptr 0, val 8),CRYPTO_num_locks(41), andCRYPTO_THREADID_set_callbackwith NULL, NULL, f1, f2, f1, NULL (1 1 1 0 0 0) plus two fresh-process orders. It also coveredCRYPTO_THREADID_set_numericon 0xaa/0x55-filled structs with 0x1234567890abcdef, 0 and ~0, with guard bytes on both sides, and none were touched. On the 2.5.4 side I read the getters back to confirm that the lock setters just store and that NULL overwrites.cryptlib.c/crypto.h.OPENSSL_init()inCRYPTO_set_locking_callbackis empty ino_init.c, so skipping it is fine.CRYPTO_exports are the 9 listed in the description. There's noCRYPTO_lock,CRYPTO_add_lock,CRYPTO_THREADID_currentor getter, so the "stored, never called" claim holds.check_conventions.py --base origin/mainpasses, and the pending stub count went 345 -> 340 on that base.Code looks right to me.
Two things:
Needs another rebase. #9949 (OCSP strings) landed and main's debt entry now says 342. The PR again conflicts in
docs/dev/debt/libSceLibreSsl.mdonly, and after mergingExport.cpphas 337NotImplemented_nid_no_patchbodies, so the number should be 337, not 340. Code files merge cleanly with current main (8a29e08).Small debt wording suggestion, not blocking. In 2.5.4 the thread id callback is also reachable from exports this library already has:
ERR_get_error/ERR_peek_error/ERR_clear_error->ERR_get_state->CRYPTO_THREADID_current->threadid_callback(err.c:1027,cryptlib.c:463). Here the queue isthread_localinsrc/Error.cpp. For example, a title whose callback returns one constant id for every thread would share one error queue on the console but get one per thread here. Nothing pushes errors yet, so it isn't observable today. Still, one clause in the entry saying the error queue is keyed by host thread, not by the guest's thread id callback, would save the next person a dig.Not checked: anything on a console.