Repository navigation
fix(libSceLibreSsl): copy DES and X509_EXTENSION guest buffers safely - #24401
oneandonlydean merged 1 commit into
Conversation
DES_ecb_encrypt, DES_set_key and DES_set_odd_parity copy the block, key and schedule bytes in through GuestCopyIn, run mbedtls on host copies and write the result with one GuestCopyOut. X509_EXTENSION_get_critical, X509_EXTENSION_get_data and X509_EXTENSION_get_object read their field through GuestCopyIn instead of memcpy. Unreadable or unwritable guest pointers throw through NotImplementedAt_nid_no_patch with errno preserved; null arguments keep their existing handling.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b9eab2161a:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libc_threads_testsbuilt cleanly. - CTest (
guest_libc_threads):1/1 Test #1298: guest_libc_threads ............... Passed 0.32 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/Threads.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1298: guest_libc_threads ...............***Exception: SegFault 0.84 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Checked _Mtx_init_nid_postfix in core/libs/prx/libc/src/Threads.cpp: verifies unwritable pointer early, allocates mutex, and safely frees mutex if the second GuestCopyOut fails before throwing std::invalid_argument
- Checked _Cnd_init_nid_postfix in core/libs/prx/libc/src/Threads.cpp: verifies unwritable pointer early, allocates condition, and safely deletes condition if the second GuestCopyOut fails before throwing std::invalid_argument
- Checked _Cnd_destroy_nid_postfix in core/libs/prx/libc/src/Threads.cpp: reads handle via GuestCopyIn, safely ignores null handles, resolves valid condition, and clears guest pointer via GuestCopyOut before deleting the condition
- Checked _ZNSt8__sce_v219_Mtx_init_with_nameEPP13pthread_mutexiPKc_nid_postfix in core/libs/prx/libc/src/Threads.cpp: clears mutex via GuestCopyOut with proper std::invalid_argument exception on unwritable memory
- Checked test coverage in core/libs/tests/GuestLibcThreads.cpp: ReadOnlyHandleSlot and UnusableHandlePointers test both unmapped and read-only memory on Linux and Windows without leaks or crashes
Looks Good To Me
b9eab21 to
d411a34
Compare
|
A batch push at 16:38 UTC+1 put the wrong commit on this branch (b9eab21, the _Mtx_init/_Cnd_init change that is #24466). I restored the branch to the commit this PR is about: d411a34, AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The change safely copies guest buffers in the six described exports; the review covered all three changed files at head d411a34351c1f87cf95e1ee27a3c372defb3b3cd.
What I ran
No commands were run. I read the prepared diff and the full text of each changed file through repo_read.py; no repository test run was performed.
Results
| Check | Result | Note |
|---|---|---|
| Changed-file review | passed | All three changed files read |
| Tests | not run | Results in the description are author-reported |
| Negative control | not run | Mutation check is author-reported |
Findings
Blocking
None.
Non-blocking
None.
Sources
The reviewed change is pinned to d411a34351c1f87cf95e1ee27a3c372defb3b3cd. Changed files read: core/libs/prx/libSceLibreSsl/Export.cpp, core/libs/tests/GuestLibreSslDes.cpp, and core/libs/tests/GuestLibreSslX509Extension.cpp.
Not verified
Build and test results, mutation checks, conventions checks, and behavior on a physical console were not independently verified. The description reports 163 passing tests and a passing conventions check.
To get this to a good state
Nothing is required.
|
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.
|
|
Windows result for head Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, The tests this PR adds or extends, AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
|
Windows test run of d411a34 merged onto current Existing runs. maskym ran Windows at d411a34 ( What this run adds. A Windows negative control against Code.
PR body. "Writes the zero-filled 128-byte schedule … as before" is right, but no test checks it (see Code). The other claims match the code and the tests. Suggestion. Lines after schedule.fill(0xff);
Require(DES_set_key_nid_postfix(weak.data(), schedule.data()) == 0);
Require(std::equal(weak.begin(), weak.end(), schedule.begin()));
Require(std::all_of(schedule.begin() + 8, schedule.end(), [](unsigned char value) { return value == 0; }));
static constexpr unsigned char readOnlyKey[8] {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
RequireRejected([] { DES_set_odd_parity_nid_postfix(const_cast<unsigned char*>(readOnlyKey)); });The first lines check the whole schedule over a dirty buffer. The last two pass a key in read-only static data, which reads fine but cannot be written back. With the pins, the merge passes 3/3, and the pinned test aborts on m5 and on m6. Negative control and mutations. Each row is one change to
Tests.
On On the merge,
AI-assisted: yes |
ligmaSec
left a comment
There was a problem hiding this comment.
Built and ran guest_libressl_des and guest_libressl_x509_extension on Linux with this head integrated. Both passed, including the new checked guest buffer cases and the existing valid-input controls.
AI-assisted: yes.
Plyxen
left a comment
There was a problem hiding this comment.
I read the diff at d411a34351. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), applied onto main at c1593e4e1dd together with other open PRs (so not an isolated build).
guest_libressl_desandguest_libressl_x509_extension: pass on both.- Control on Windows (the same tree and tests, with the sources of this PR and of the other PRs in the batch put back to
main's): both crash, on reads of addresses 0x10 and 0x18.
Not checked: a title.
AI-assisted: yes (Claude Code)
What
Six libSceLibreSsl exports in
Export.cppno longer read or write guest buffers directly. All of them take caller-supplied guest memory (DES blocks, keys and key schedules, and anX509_EXTENSIONthe title holds), so none is a host-handle false positive.DES_ecb_encryptcopies the 8-byte input block and the 8 key bytes of the schedule in throughGuestCopyIn_nid_no_patch, runs mbedtls on host copies and writes the output block with oneGuestCopyOut_nid_no_patch. In-place calls (input == output) still work.DES_set_keycopies the key in and writes the zero-filled 128-byte schedule with oneGuestCopyOut_nid_no_patch, as before.DES_set_odd_paritycopies the key in, sets parity on the host copy and writes it back. The audit does not list it (it calls mbedtls, notmemcpy), but it dereferenced the guest key the same way.X509_EXTENSION_get_critical,X509_EXTENSION_get_dataandX509_EXTENSION_get_objectread their field throughGuestCopyIn_nid_no_patchinstead ofmemcpy.errno is preserved, as
CRYPTO_THREADID_set_numericin the same file already does. An unreadable or unwritable pointer throws throughNotImplementedAt_nid_no_patch, which is how this library rejects them elsewhere (SslCtx.cpp,Bio.cpp). Null arguments keep their existingstd::invalid_argument/ null-return handling, and results for valid inputs are byte-for-byte unchanged; the existing DES known-answer and extension tests pass unchanged.tools/guest_pointer_audit.py libSceLibreSslno longer lists the five audited functions.tools/progress.py --module libSceLibreSslreports 269/402 on bothmainand this branch. No debt entry describes the old behaviour, so there is no debt fragment. No listed function was a false positive. Not changed inExport.cpp:OCSP_basic_verify,SSL_CTX_use_certificate_ASN1,SSL_get_peer_cert_chain,SSL_get_peer_certificateandd2i_PKCS12_bio(separate topics), andSSL_get1_session(edited by #23139 and #23336).Overlap:
python3 tools/pr_overlap.py --names DES_ecb_encrypt DES_set_key DES_set_odd_parity X509_EXTENSION_get_critical X509_EXTENSION_get_data X509_EXTENSION_get_objectlists 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-des-extension-guest-pointers(re-run on 2026-11-20 againstmain0a025bd) could not compare #11146, #11466, #13285, #13547, #15278, #15279 and #15280 (they conflict withmain) onExport.cpp; none of their diffs adds or removes a line that mentions the DES orX509_EXTENSIONfunctions.Tested
Arch Linux, GCC, Release, re-run on 2026-11-20 after rebasing onto
main0a025bd. All libSceLibreSsl tests andpublic_headerspassed (ctest --test-dir build -R 'guest_libressl_|guest_libre_ssl|guest_digest_extents|libressl_|public_headers', 163/163).New cases pass an unmapped pointer (0x10) and require a throw with errno preserved:
GuestLibreSslDes.cpp: unmapped input, schedule and output forDES_ecb_encrypt(the output block must stay untouched), unmapped key and schedule forDES_set_key(the schedule must stay unchanged), unmapped key forDES_set_odd_parity.GuestLibreSslX509Extension.cpp: unmapped extension for each of the three getters.Mutation check: with
Export.cppreset toorigin/main,guest_libressl_desandguest_libressl_x509_extensioncrash with SegFault; with the change both pass.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)