fix(libSceLibreSsl): copy cipher, key, rand, X509V3 and PEM guest pointers safely #22476
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22476"
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-17T17:29:31Z.
What
Six libSceLibreSsl exports no longer dereference guest pointers. I checked the host-allocated-object exception first, and none of the six applies. The objects are all guest memory:
EVP_PKEYandRSAcome from the guestmalloc.SSL_CTXis a guest structure;SslCtx.cppalready reads it throughGuestCopyIn.EVP_CIPHERhas a public layout, andEvpCipherCtx.cppalready copies it in throughLoadCipher.RAND_file_namebuffer and thePEM_read_RSAPrivateKeyoutput pointer are guest memory supplied by the caller.Changes:
SSL_CTX_set_cipher_list(src/CipherList.cpp) reads the context's internal pointer, its cipher list and its by-id list throughGuestCopyIn_nid_no_patch. Before the lists are rebuilt, it checks withGuestWritable_nid_no_patchthat both list fields are writable, so a read-only context fails before the old lists are freed. It writes the new lists back throughGuestCopyOut_nid_no_patch.EVP_CIPHER_block_size(src/EvpCipher.cpp) andEVP_PKEY_id(src/PkeyId.cpp) copy the block size and the key type in.RAND_file_name(src/Runtime.cpp) builds the path on the host and writes at most the requested bytes with oneGuestCopyOut_nid_no_patch. Nothing is sized from the guest length.PEM_read_RSAPrivateKey(src/PemX509.cpp) checks that the output pointer is readable and writable before it reads the key. It then copies the old key in and the new key out.X509V3_EXT_print(src/X509V3Print.cpp) copies in the extension, its object (with the OID bytes when it has no NID) and its value, and prints from host copies. The OID and value bytes are read in 4 KiB chunks, and the host buffer only grows by bytes that were already read. A huge length on a short value fails with the normal guest error instead of causing a large host allocation.errno is preserved, as the helpers in
SslCtx.cppandEvpCipherCtx.cppalready do. An unreadable or unwritable pointer now throws throughNotImplementedAt_nid_no_patch, which is how this library already rejects them. It is no longer dereferenced. Results for valid inputs are byte-for-byte the same, and the existing tests for all six functions pass unchanged.tools/guest_pointer_audit.py libSceLibreSslno longer lists any of the six functions.tools/progress.py --module libSceLibreSslshows 302 done on bothorigin/mainand this branch. The debt entries for these functions describe layouts, sources and null handling, not unchecked guest access, so there is no debt fragment. No listed function was a false positive.Not changed: the
rulesstring ofSSL_CTX_set_cipher_list, which the audit does not list.LibreSslObjectNid_nid_no_patchand the extension value decoders are also unchanged;X509V3_EXT_printnow hands them only host copies.Overlap:
python3 tools/pr_overlap.py --names SSL_CTX_set_cipher_list EVP_CIPHER_block_size EVP_PKEY_id RAND_file_name X509V3_EXT_print PEM_read_RSAPrivateKeylists only #17299 and #17303. Those PRs name libSceLibreSsl3 parent-export aliases and change no file incore/libs/prx/libSceLibreSsl/.python3 tools/pr_overlap.py --branch fix/libressl-misc-guest-pointersreports no overlap with open pull requests.Tested
Arch Linux, GCC, Release. All 96 libSceLibreSsl tests passed (
ctest --test-dir build -R 'guest_libressl_|guest_libre_ssl|guest_digest_extents|libressl' -E libressl3), andctest -R '^public_headers'passed (65/65).New cases pass an unmapped pointer (0x10) or read-only memory to each export, and each call must throw with errno preserved:
tests/CipherList.cpp: unmapped context, unmapped internal state, read-only internal state. The cipher list must stay unset.GuestLibreSslEvpCipher.cpp: unmapped cipher.GuestLibreSslPkeyId.cpp: unmapped key.GuestLibreSslRuntime.cpp: unmapped buffer with sizes 1, 13 andSIZE_MAX, and a read-only buffer.GuestLibreSslPemPrivateKey.cpp: unmapped and read-only output pointer, with no error queued.GuestLibreSslX509V3Print.cpp: unmapped extension, object and value. The OID and the value are also placed just before a guard page: they must print exactly as before, and anINT_MAXlength must be rejected without changing the allocations.Mutation checks:
origin/main,guest_libressl_cipher_list,guest_libressl_evp_cipher,guest_libressl_pkey_id,guest_libressl_runtime,guest_libressl_x509v3_printandguest_libressl_pem_private_keycrash with SegFault.SSL_CTX_set_cipher_list,guest_libressl_cipher_listfails at line 370.python3 tools/check_conventions.py --base origin/mainandpython3 tools/debt_fold.py --checkpassed.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-17T17:33:44Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f2cf79de26:tools/check_conventions.pypassed.guest_libressl_cipher_list_tests,guest_libressl_evp_cipher_tests,guest_libressl_pem_private_key_tests,guest_libressl_pkey_id_tests,guest_libressl_runtime_tests,guest_libressl_x509v3_print_testsbuilt cleanly.guest_libressl_pem_private_key,guest_libressl_runtime,guest_libressl_pkey_id,guest_libressl_evp_cipher,guest_libressl_x509v3_print,guest_libressl_cipher_list,guest_libressl_cipher_list_allocator):core/libs/prx/libSceLibreSsl/src/CipherList.cpp,core/libs/prx/libSceLibreSsl/src/EvpCipher.cpp,core/libs/prx/libSceLibreSsl/src/PemX509.cpp,core/libs/prx/libSceLibreSsl/src/PkeyId.cpp,core/libs/prx/libSceLibreSsl/src/Runtime.cpp,core/libs/prx/libSceLibreSsl/src/X509V3Print.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-23T03:45:04Z.
Review: APPROVED
Reviewed — looks good
The guest pointer handling changes at head
f2cf79de26f2b5e76a1577338c295d3f17a77512appear sound based on the changed implementation and tests read; author-reported test results were not independently run.What I ran
Read the prepared review artifacts and targeted repository source at the pinned head. No build or tests were run.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Tests, builds, and runtime behavior were not independently verified. Read all changed implementation files and the changed test files’ added lines as listed in
review/README.md; no changed files were excluded. Readreview/description.md,review/commits.md,review/manifest.json, andreview/diff.patch.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:24:06Z.
Review: COMMENTED
Built the submitted LibreSSL implementations and ran the six changed fixtures on Linux. Cipher list, EVP cipher, PEM private key, PKEY ID, runtime, and X509V3 print all passed with the pinned project libraries. The cases exercise the guest pointer checks and normal API behavior.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.