feat(libSceLibreSsl): implement SSL_get1_session and session reference release #23139
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23139"
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 Callimann8 on 2026-11-18T19:09:49Z.
What
Implements
SSL_get1_sessionin libSceLibreSsl and the reference-dropping path ofSSL_SESSION_free(libSceLibreSsl3 reaches both through its parent forwardssoWa0pMndTMandhIb43mo9ubQ). A connection with a session madeSSL_get1_sessionthrow, and every non-nullSSL_SESSION_freethrew. Clients call the pair to keep a session for resumption and release it later.LibreSslSessioninApi.hppmapsreferencesat offset 160, after the fields of LibreSSL 2.5.4'sssl_session_ston LP64; the size (232) and thecipheroffset (168) are unchanged and asserted.Export.cpptosrc/SslSession.cpp, next toSSL_get_session, with the same signatures:SSL_get1_sessionfollowsssl_sess.c: no session returns null, otherwise the count goes up by one and the session is returned. A compare-and-swap loop stands in for theCRYPTO_LOCK_SSL_SESSIONlock. A count already atINT_MAXthrowsstd::overflow_errorand is left unchanged, where LibreSSL's plainreferences++would overflow a signedint.SSL_SESSION_freefollowsssl_sess.c: null returns at once, and a release that leaves references returns after the decrement. A count of 0 or less throwsstd::invalid_argumentand is left unchanged, so the count never goes negative.SslSession.cppgetters do.docs/dev/debt/changes/feat-libressl-ssl-get1-session.mdupdates both entries.Releasing the last reference still throws (
NotImplemented_nid_no_patch) before touching the count, which stays at 1, because freeing needs the session's internal state, peer certificate and cipher stack, which are not mapped.Tested
Linux (Ubuntu, GCC), unit test only; nothing checked on a console or in a title.
core/libs/tests/GuestLibreSslSslSession.cppaddsTestGet1Session(null connection throws, no session returns null, two calls return the session and raise the count from 1 to 3, a count atINT_MAXthrows and stays atINT_MAX) andTestSessionFree(null is a no-op, releases from 3 to 1 decrement, the last release throws and leaves the count at 1, counts of 0 and -1 throw and stay unchanged).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 PrivacyOnion on 2026-11-18T19:19:12Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
96dcbca960:tools/check_conventions.pypassed.guest_libressl_ssl_session_testsbuilt cleanly.guest_libressl_ssl_session):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/SslSession.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T19:25:44Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent the session reference count from wrapping or becoming negative on invalid or exhausted reference operations.
What I ran
Reviewed head
96dcbca96082c2925cab6077fecbce26d6e103da; no build or tests were run. Read the description, commits, manifest, diff, and all five changed files listed as reviewed. The PR description reports a Linux unit test run; I did not run it.Results
Findings
Blocking
core/libs/prx/libSceLibreSsl/src/SslSession.cpp:43:SSL_get1_sessionincrements a signedintwithout checking for overflow. AtINT_MAX,fetch_add(1)causes signed integer overflow, which is undefined behavior and can corrupt the reference count; subsequent frees may then take the wrong path. Use a checked atomic increment and define the failure behavior when the count cannot be increased.Non-blocking
None.
Not verified
I did not run tests, a build, console firmware, or title behavior. The PR description reports
ctest -R guest_libressl_ssl_sessionpassed on Ubuntu with GCC. All changed files inmanifest.jsonwere included and read; none were excluded byfiles.json(which is not available through the reader interface).To get this to a good state
Guard the increment against reference-count overflow, then rerun the session unit test on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T19:51:23Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
46df37513d:tools/check_conventions.pypassed.guest_libressl_ssl_session_testsbuilt cleanly.guest_libressl_ssl_session):core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/SslSession.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T19:54:14Z.
Review: COMMENTED
Reviewed — comments
The increment and non-final release paths are implemented and covered by added unit cases, but the final release path remains intentionally unimplemented, so this review cannot support approval of the advertised release behavior.
What I ran
Reviewed head
46df37513d60a6ee3ec178fbddbdfcc6c6882b62. Read the prepared description, commits, manifest, diff, and all changed files listed as included. Read targeted repository context inSslSession.cpp,Api.hpp, the session test file, andExport.cpp; searched callers and atomic reference usage. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
SSL_SESSION_freethrows when the count is 1 and leaves it unchanged, so a caller cannot release the final reference. This limitation is explicitly documented in the PR description and debt fragment; follow up by mapping the required session state and implementing final cleanup. The current behavior is visible atcore/libs/prx/libSceLibreSsl/src/SslSession.cpp:59.Not verified
ctest -R guest_libressl_ssl_sessionresult is author supplied.To get this to a good state
Nothing is required. Optional follow-up: implement final-reference cleanup when the unmapped session state is available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:19:14Z.
Review: APPROVED
Reviewed — looks good
The change implements session reference acquisition and non-final release, with layout assertions and focused unit coverage; I found no verified blocking defect in the reviewed files.
What I ran
Reviewed head
e3ac8cbf9fb3f3ea1e87a6f38f31fae1483d8dd4usingrepo_read.pyto inspect the prepared diff and changed source files. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test or build was run. Console behavior was not verified. The prepared manifest lists five changed files, all included; each was read:
core/libs/prx/libSceLibreSsl/Export.cpp,core/libs/prx/libSceLibreSsl/include/Api.hpp,core/libs/prx/libSceLibreSsl/src/SslSession.cpp,core/libs/tests/GuestLibreSslSslSession.cpp, anddocs/dev/debt/changes/feat-libressl-ssl-get1-session.md. No files were excluded in the supplied manifest.To get this to a good state
Nothing is required.