fix(libSceLibreSsl): copy SSL_CTX guest pointers safely #22128
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22128"
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 domx4q on 2026-11-17T06:18:43Z.
What
fix(libSceLibreSsl): copy SSL_CTX guest pointers safelyThe flagged exports in
core/libs/prx/libSceLibreSsl/src/SslCtx.cppnow reach the guestSSL_CTXand its internal state throughGuestCopyIn,GuestCopyOutandGuestWritable, using errno-preserving wrappers like those insrc/Cipher.cpp.SSL_CTX_newis still a stub, so everySSL_CTXthese functions receive is guest memory, not a host-allocated handle.SSL_CTX_ctrlreadsctx->internalthrough a copy. Each command then reads, exchanges or updates its field through a copy. The 48-byte ticket keys (parg) are copied in or out as a whole, and setting them first checks that all three internal key fields are writable.SSL_CTX_CTRL_GET_EXTRA_CHAIN_CERTSreadsextraCertsand writes it topargthrough copies.SSL_CTX_check_private_keyreadsinternalandinternal->certthrough copies.SSL_CTX_set_verifychecks that the callback field is writable, then writesverifyModeanddefaultVerifyCallbackthrough copies.SSL_CTX_set_session_id_contextcopiessidCtxin and checks that the destination is writable. It then writessidCtxLengthand the bytes through copies.SSL_CTX_get_ex_datareadsinternalandexDatathrough copies.If a guest pointer cannot be read or written, the call throws through
NotImplementedAt_nid_no_patch, keepserrnoand leaves guest memory unchanged. It no longer dereferences the pointer on the host. Results for valid inputs do not change.python3 tools/guest_pointer_audit.py libSceLibreSslno longer lists anything insrc/SslCtx.cpp.Not changed: the other exports in
SslCtx.cpp(SSL_CTX_callback_ctrl,SSL_CTX_set_msg_callback, the getters and others) still go through the reference-returningContext/Internalhelpers, which the audit does not flag. That is a follow-up.No debt fragment. The existing
SslCtx.cppdebt entries describe LibreSSL behaviour, not unchecked guest access, and that behaviour does not change.Tested
Arch Linux, GCC, Release (
-DBUILD_TESTING=ON).guest_libressl_ssl_ctx_fieldsgainsTestGuestPointers, which covers:0x10).internalpointer is unmapped.parg(extra chain certificates, get and set ticket keys) and an unmappedsidCtx.internalreached through a writable context, and a fully read-only context. Getters must still work. Setters,Options, ticket key set andset_verifymust be rejected.sidCtx.set_session_id_contextmust be rejected without writingsidCtxLength.Each rejection must throw
std::runtime_errorwitherrnounchanged, and the bytes must stay the same.ctest -R libressl -E libressl3: 91/91 passed.ctest -R public_headers: 65/65 passed.Mutation checks, each run against the new test:
ctx->internalinSSL_CTX_ctrl, a directreadAheadexchange, a direct*pargwrite for extra chain certificates, directmemcpyfor get and set ticket keys, directctx->internal->certincheck_private_key, a directmemcpyofsidCtx, direct->exDatainget_ex_data.set_verify, removing the writability check inset_session_id_context(straddling-page test).python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/debt_fold.py --checkfails onmainalready (docs-nkwebkit-drop-readded-count-lines.md). This PR did not cause it.Overlap
python3 tools/pr_overlap.py --names SSL_CTX_ctrl SSL_CTX_check_private_key SSL_CTX_set_verify SSL_CTX_set_session_id_context SSL_CTX_get_ex_datalists #17299 and #17303 (LibreSsl3 parent-export alias naming). Neither touchescore/libs/prx/libSceLibreSsl/(checked withgh pr diff --name-only).python3 tools/pr_overlap.py --branch fix/libressl-ssl-ctx-guest-pointers: no overlap with open pull requests (1747 probed).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-17T06:26:14Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
efa8e2d84b:tools/check_conventions.pypassed.guest_libressl_ssl_ctx_fields_testsbuilt cleanly.guest_libressl_ssl_ctx_fields):core/libs/prx/libSceLibreSsl/src/SslCtx.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me