Repository navigation
feat(libSceLibreSsl): implement the SSL and SSL_CTX ex_data index registry as LibreSSL 2.5.4 does - #11340
Conversation
…istry as LibreSSL 2.5.4 does SSL_get_ex_new_index and SSL_CTX_get_ex_new_index number their indices per class from 0, SSL_get_ex_data_X509_STORE_CTX_idx allocates its class-5 index once, and CRYPTO_cleanup_all_ex_data releases every class. An allocation failure returns -1 with ERR_R_MALLOC_FAILURE queued. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Progress report (74acfad → 63ef393)📈 System libraries: 51.86% (+0.03%, +4 implemented functions) ✅ 4 implemented
Changed libraries (implemented exports)
|
MarcZX10
left a comment
There was a problem hiding this comment.
The registered class indices and cleanup behavior match the cited LibreSSL 2.5.4 implementation, and the new test covers separate counters, cached store-context indexing, cleanup and concurrent registrations. I independently compiled src/ExData.cpp with tests/ExData.cpp using GCC 12 (-std=c++20 -Wall -Wextra -Werror -pthread); those test cases passed with a no-op stub for LibreSslPutError_nid_no_patch. This was a focused source-level check, not a full product build or allocation-failure test.
The branch is 32 commits behind current main (merge preview is clean). CONTRIBUTING.md requires branches to be based on and kept up to date with main; please rebase and rerun the focused guest_libressl_ex_data test on the resulting head before approval. The hosted product build jobs are path-skipped.
MarcZX10
left a comment
There was a problem hiding this comment.
Blocking API issue: both new declarations use void* for newFunction, dupFunction and freeFunction. LibreSSL 2.5.4 declares these as callback function pointers (CRYPTO_EX_new*, CRYPTO_EX_dup*, CRYPTO_EX_free*) in its SSL API. C++ does not implicitly convert function pointers to object pointers, so a client with valid typed callbacks cannot call either declaration.
I confirmed this with a minimal source including this PR's Api.hpp and passing callbacks with the LibreSSL signatures: g++ -std=c++20 -Wall -Wextra -Werror fails on all three callback arguments to SSL_get_ex_new_index_nid_postfix. Please declare callback-compatible function pointer types for the target ABI, use them in both public declarations and implementations, and add a compile/regression case that passes non-null callbacks (they can remain stored but uninvoked while SSL/SSL_CTX accessors are unimplemented). Then rerun guest_libressl_ex_data on the updated head.
The previously reported focused test passed, but it passes only null callbacks and therefore does not exercise this API contract. The branch is also 32 commits behind current main; please rebase it while addressing this and rerun the focused test there.
|
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.
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.
|
…tion pointer types SSL_get_ex_new_index and SSL_CTX_get_ex_new_index took the new, dup and free callbacks as void*, which a caller passing real callbacks can't convert to. They now take LibreSslExNew, LibreSslExDup and LibreSslExFree, the guest-ABI forms of CRYPTO_EX_new, CRYPTO_EX_dup and CRYPTO_EX_free from LibreSSL 2.5.4's ossl_typ.h. Reported by @MarcZX10. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@MarcZX10 thanks, that was a real API bug and my null-only test hid it. Fixed in
Windows 11, GCC 15.2.0, full build on the merged head: all 13 Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine. |
…-indices # Conflicts: # core/libs/prx/libSceLibreSsl/include/Api.hpp
|
Merged current Windows 11, GCC 15.2.0, full build of the merged head:
Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine. |
jotitadev
left a comment
There was a problem hiding this comment.
Linux run of the current head, since the description lists only Windows.
Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON. Head 63ef393ee merged onto main cb45ae2dd.
- Build ok. All 19
guest_libressl*tests pass, including the newguest_libressl_ex_data(50 of 50 repeats), and so dopatched_librariesandconventions_unknown_nids. - The four exports now live in
src/ExData.cppinstead ofExport.cpp. In the patchedlibSceLibreSsl.prxthey appear under their NIDs (PGsWNnS7CE8,2k6m8dF7sPc,E5opvIVafTc,FnLDy4R08cQ) at the same addresses as the_nid_postfixsymbols in the unpatched one, so moving them out ofExport.cppdoes not lose the patching. - Replacing the four bodies with
main'sNotImplemented_nid_no_patchand keeping the test aborts withSSL_get_ex_new_index_nid_postfix not implemented. Registering every index in the SSL class instead ofclasses[classIndex]failsSSL_CTX indices are counted apart from SSL ones, so the test also checks that the classes are separate.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Dismissing a stale review: the requested changes were addressed after it (new head) and the merge queue blocks on it. Please request changes again if anything is still open.
|
macOS run of head All 23 AI-assisted: yes |
|
Checked the index numbering and cleanup against LibreSSL 2.5.4 |
What
SSL_get_ex_new_index,SSL_CTX_get_ex_new_index,SSL_get_ex_data_X509_STORE_CTX_idxandCRYPTO_cleanup_all_ex_dataare parameterless placeholders that throw. This implements them as LibreSSL 2.5.4 does. Discussion #8981 places 2.5.4 on firmware 13.40.In 2.5.4:
SSL_get_ex_new_indexandSSL_CTX_get_ex_new_index(ssl_lib.c:2828-2854) callCRYPTO_get_ex_new_indexwith class 1 (CRYPTO_EX_INDEX_SSL) or 2 (CRYPTO_EX_INDEX_SSL_CTX).argl,argpand the three callbacks for the class and returns the class's next index, from 0. An allocation failure queuesCRYPTOerror(ERR_R_MALLOC_FAILURE)(library 15, reason 65) and returns -1.SSL_get_ex_data_X509_STORE_CTX_idx(ssl_cert.c:133-160) allocates one index in class 5 (X509_STORE_CTX) withargp"SSL for verify callback" the first time and caches it in a static.CRYPTO_cleanup_all_ex_datafrees every class's table, so numbering restarts at 0. The cached verify-callback index isn't reset.The callbacks are declared as
LibreSslExNew,LibreSslExDupandLibreSslExFree, the guest-ABI forms ofCRYPTO_EX_new,CRYPTO_EX_dupandCRYPTO_EX_free(ossl_typ.h:163-168), so callers can pass real callbacks.src/ExData.cppkeeps one list per class under a mutex and follows those rules.std::bad_allocfrom the list is caught and reported as the 2.5.4 malloc failure, so no host exception reaches the guest. No other export of this library allocates in class 5, so the verify-callback index is always 0.CRYPTO_cleanup_all_ex_datareturnsvoidas in 2.5.4.The stored
argl,argpand callbacks are never called: no export creates anSSLorSSL_CTX, andSSL_get_ex_data/SSL_set_ex_datastill throw. The new debt entry says so. #10248 leavesCRYPTO_cleanup_all_ex_datathrowing "because no ex_data is implemented yet", and #10878 lists it as still throwing; this adds that piece.Tested
Windows 11, WinLibs GCC 15.2.0 r7, full Release build of d91daf8 (current
mainmerged in).guest_libressl_ex_data(tests/ExData.cpp):guest_libressl*tests pass, 3 runs; the full build had no failed steps.guest_libressl_ex_dataat "SSL_CTX indices are counted apart from SSL ones" (2 runs). Main's placeholders take no arguments, so the test can't be built against them.tools/check_conventions.py --base origin/mainpasses.Overlap
pr_overlapfinds no PR implementing these exports. The conflicts are text-only:SSL_CTX_*placeholders next toSSL_CTX_get_ex_new_indexinExport.cppandApi.hpp.docs/dev/debt/libSceLibreSsl.md.Whichever lands second keeps both.
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)🤖 Generated with Claude Code