fix(libSceLibreSsl): check SSL and SSL_CTX guest records in lifecycle exports #24415
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24415"
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-20T16:01:55Z.
What
SSL_free,SSL_CTX_free,SSL_new,SSL_set_fdandSSL_get_fd(src/SslLifecycle.cpp) no longer dereference theSSL/SSL_CTXthey are handed before checking it. Both objects are guest memory:SSL_newandSSL_CTX_newallocate them (and the internal state) with the guestcalloc, andSslCtx.cppalready readsSSL_CTXthroughGuestCopyIn(#22128). They are not host-handle false positives.SSL_free,SSL_CTX_free,SSL_newandSSL_set_fdcopy the whole record in throughGuestCopyIn_nid_no_patchand check it withGuestWritable_nid_no_patchbefore releasing a reference or changing it; the reference count is then released atomically on the checked object, asSSL_up_refin libSceLibreSsl3 does.SSL_CTX_freeandSSL_newalso check the context's internal state before using it.SSL_newandSSL_set_fdcheck before they allocate, so a rejected call allocates nothing (previouslySSL_set_fdcreated its socket BIO first).SSL_get_fdcopies the record in and readsrbiofrom the copy.The teardown and population helpers (
DestroySsl,PopulateSsl,SetBio) are unchanged and run on the checked object. errno is preserved, as the helpers inSslCtx.cppdo. An unreadable or unwritable pointer throws throughNotImplementedAt_nid_no_patch, which is how this library already rejects them. Null handling, error queueing and results for valid inputs are unchanged; the existing lifecycle tests pass unchanged.GuestWritable_nid_no_patch(libc) no longer allocates host memory. It built aHostMapping::Mappingwith astd::stringpath and, on kernels withoutPROCMAP_QUERY(before 6.11, for example Ubuntu 24.04), read/proc/self/mapsthroughstd::ifstream. With the new checks inSSL_freeandSSL_CTX_free, the existingTestExDataTeardownUnderHostAllocationFailurethrewstd::bad_allocthere, and the unwinder's own allocations recursed until the stack overflowed. The newHostMapping::FindProtectionreturns only the end and write permission of the covering mapping, throughPROCMAP_QUERYwithout a name buffer or by parsing/proc/self/mapsfrom a fixed buffer. A second ctest entry,guest_libressl_ssl_lifecycle_maps_scan, runs the lifecycle tests withAPS5_NO_PROCMAP_QUERY=1.False positive left unchanged:
SSL_CTX_new'smethod. The audit lists it, but the onlySSL_METHODs are the library's own static host objects returned byTLS_client_method,SSLv23_server_methodand the DTLS getters (src/SslMethod.cpp), so it is a library-owned handle, not guest memory.tools/guest_pointer_audit.py libSceLibreSslno longer lists the five functions (only theSSL_CTX_newfalse positive remains for this file).tools/progress.py --module libSceLibreSslreports 269/402 on bothmainand this branch. No debt entry describes the old behaviour, so there is no debt fragment.Overlap:
python3 tools/pr_overlap.py --names SSL_CTX_free SSL_new SSL_free SSL_set_fd SSL_get_fdlists only #17299 and #17303, which name libSceLibreSsl3 parent-export aliases and change no file incore/libs/prx/libSceLibreSsl/.python3 tools/pr_overlap.py --branch fix/libressl-ssl-handle-guest-pointers(re-run on 2026-11-20 againstmain0a025bd3c6) reports no overlap with open pull requests (the new test is placed away from the lines #23078, #23088 and #23336 add to the same test file).Tested
Arch Linux, GCC 16, Release, on 2026-11-20 at
c55bfa776f. All libSceLibreSsl tests andpublic_headerspassed, both normally and withAPS5_NO_PROCMAP_QUERY=1(ctest --test-dir build -R 'guest_libressl_|guest_libre_ssl|guest_digest_extents|libressl_|public_headers', 164/164).guest_posix_filesystem, which checksGuestWritableon ranges that cross mappings, passed in both modes.Ubuntu 24.04 container (gcc-13 13.3.0, Ninja, Release):
ctest -R guest_libressl_ssl_lifecyclepassed 2/2. At the previous head057916706e,APS5_NO_PROCMAP_QUERY=1madeguest_libressl_ssl_lifecyclecrash with SegFault, as the review reported.New
TestGuestPointersincore/libs/tests/GuestLibreSslSslLifecycle.cpp(run under the existing leak check): all five exports get an unmappedSSLorSSL_CTX(0x10);SSL_CTX_free,SSL_new,SSL_freeandSSL_set_fdget read-only copies of real objects (the copies must stay unchanged;SSL_get_fdstill reads them);SSL_newandSSL_CTX_freeget a context whose internal state is unmapped. Each call must throw with errno preserved, allocate nothing, and leave the real context's reference count unchanged.Mutation checks: with
src/SslLifecycle.cppreset toorigin/main,guest_libressl_ssl_lifecyclecrashes with SegFault; with the change it passes. With only theGuestWritablechange inGeneral.cppreverted,guest_libressl_ssl_lifecycle_maps_scancrashes with SegFault; with it the test passes.python3 tools/check_conventions.py --base origin/mainpassed.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-20T16:19:05Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
057916706e:tools/check_conventions.pypassed.guest_libressl_ssl_lifecycle_testsbuilt cleanly.guest_libressl_ssl_lifecycle):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T16:45:50Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c55bfa776f:tools/check_conventions.pypassed.guest_libressl_ssl_lifecycle_testsbuilt cleanly.guest_libressl_ssl_lifecycle,guest_libressl_ssl_lifecycle_maps_scan):core/libs/prx/libSceLibreSsl/src/SslLifecycle.cpp,core/libs/prx/libc/include/specifics/linux/HostMapping.hpp,core/libs/prx/libc/src/General.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-21T08:49:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the author-reported checks support the intended guest-pointer validation behavior.
What I ran
Reviewed head
c55bfa776f167b1a8e3a4af10bfc3eebb2ed7a76usingrepo_read.pyto read the prepared description, commits, manifest, diff, and changed source ranges. I ran no tests or build commands.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports 164/164 tests passed on Arch Linux with GCC 16, lifecycle tests passed 2/2 on Ubuntu 24.04 with GCC 13, and convention checks passed. These were not run during this review.
files.jsonwas unavailable through the reader, so excluded-file details were not verified. No files were excluded in the supplied manifest; all five reviewed changed files had full text available and were read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Romannachwievor on 2026-11-27T00:37:42Z.
Review: COMMENTED
macOS measurement on an M1 (x86_64 build, Release,
BUILD_TESTING=ON, same flags as my local nightly).Base is
f42464a6fe:origin/mainata901acf65cplus #17425, #11049, #26739 and #27621, which the macOS build needs (without #17425 the curl backend builds arm64 and 31 tests do not run; without #27621 libwebrtc does not build).PR head
c55bfa776f, merged into the base as20bc4cfbbb.Tests:
tools/select_tests.py selectpicked 6618 of 6781 tests and 3600 build targets. Tests whose names match^agc_|videoout|vulkan|shader|gpuare dropped from the selection because the PR touches no AGC, shader recompiler or VideoOut code. 4526 ran withctest -j8 --timeout 300(1179 s).guest_net_oob_inlineandguest_main_stack_movepassed on the base and passed on the first serial retry with the PR, so they look like-j8load flakesguest_libressl_ssl_lifecycle(touched by the PR) passed on base and PRA test counts as broken by the PR only if it passes on the base and fails 3 of 3 serial reruns with the PR. None did.
The only build failure, on both base and PR, is
core/libs/prx/libSceAgcDriver/tests/execution/PipelinedFlushReadOrder.cpp:232(use of undeclared identifier 'mapped'). It is already on main.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T14:51:23Z.
Review: COMMENTED
Built and ran
guest_libressl_ssl_lifecycleon Linux with this head integrated. It passed. I checked the added validation for SSL and SSL_CTX records and the existing file-descriptor behavior covered by the fixture.AI-assisted: yes.