Repository navigation
fix(libSceLibreSsl): queue the EC, ECDSA and ECDH errors of LibreSSL 2.5.4 - #26417
Conversation
…2.5.4 Ec.cpp returned every failure with an empty error queue. LibreSSL 2.5.4 queues a reason for each of them in ec_curve.c, ec_key.c, ecp_oct.c, ecs_ossl.c and ech_key.c: - an unknown curve NID; - an invalid form or a short buffer in EC_POINT_point2oct; - missing parts of a key in EC_KEY_generate_key, EC_KEY_set_public_key, EC_KEY_check_key, ECDSA_sign, ECDSA_verify and ECDH_compute_key; - a public key at infinity, off the curve or not matching the private key in EC_KEY_check_key; - r or s out of range and a sum at infinity in ECDSA_verify; - a peer point at infinity, a short output and a failing KDF in ECDH_compute_key. Return values are unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…-queue Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
Built libSceLibreSsl and ran guest_libressl_ec_error_queue_tests on Linux (x86-64, GCC 11).
- On this branch: passes.
- Control — reverted
src/Ec.cpptoorigin/main, kept the new test: aborts at line 171. The test genuinely exercises the queued reason codes.
This queues the LibreSSL 2.5.4 ERR_LIB_EC/ERR_LIB_ECDSA/ERR_LIB_ECDH reason codes for the failures the port returns, pinned to specific 2.5.4 source files. The debt fragment is unusually thorough: it enumerates exactly which failures queue codes and which throw instead (ASN.1 decode, allocation/BN/arithmetic, EC_POINT_new/oct2point, infinity peer point), documents the OPENSSL_BN_ASM_MONT divergence, and — importantly — flags that libSceLibreSsl3 forwards these exports so its callers now get the 2.5.4 ERR_LIB_ECDSA/ERR_LIB_ECDH codes where 4.0.0 would queue ERR_LIB_EC ones. That cross-library consequence is exactly the kind of thing a reviewer should confirm is intended.
malekaifa
left a comment
There was a problem hiding this comment.
Reviewed exact head 4c70af631621aed6fd3548e1f27a169977d58151 against LibreSSL 2.5.4 EC/ECDSA/ECDH source at 2e2c612066aa993717528a0249c15c51128d61cb.
The added queue behavior matches the source branches covered by this port: unknown groups and EC key validity failures use the EC reasons; ECDSA missing parameters, out-of-range r/s and EC-arithmetic propagation use the 2.5.4 ECDSA library/reasons; and ECDH preserves the source's unusual check order, including outlen > INT_MAX before key validation, no-private-value before group use, key-truncation before buffer allocation, and the EC→ECDH nested failures. The new tests also preserve earlier queued errors rather than accidentally clearing them. The independent Linux build/test plus old-code control exercises these changes, and exact-head conventions/intake/labels/eligibility/report/portability are green.
The debt entry explicitly records the intentional gaps and the libSceLibreSsl3 cross-version consequence (2.5.4 ECDSA/ECDH library codes where 4.0.0 differs). A current hosted Windows run is still in progress, so this review is not a claim that that run has finished.
AI-assisted: yes
|
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.
|
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4c70af6316:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl_ec_error_queue_testsbuilt cleanly. - CTest (
guest_libressl_ec_error_queue):1/1 Test #4701: guest_libressl_ec_error_queue .... Passed 0.12 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibreSsl/src/Ec.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4701: guest_libressl_ec_error_queue ....Subprocess aborted***Exception: 0.55 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified that EC_POINT_point2oct returns 0 and queues EC_R_INVALID_FORM on invalid form, and EC_R_BUFFER_TOO_SMALL on insufficient buffer length
- Verified that EC_KEY_generate_key, EC_KEY_set_public_key, and EC_KEY_check_key correctly queue ERR_R_PASSED_NULL_PARAMETER, EC_R_POINT_AT_INFINITY, EC_R_POINT_IS_NOT_ON_CURVE, and EC_R_INVALID_PRIVATE_KEY on their respective error paths
- Verified that ECDSA_sign and ECDSA_verify queue ERR_LIB_ECDSA with ERR_R_PASSED_NULL_PARAMETER, ECDSA_R_MISSING_PARAMETERS, ECDSA_R_BAD_SIGNATURE, and properly chain EC_R_POINT_AT_INFINITY / ECDSA_R_ERR_LIB_EC on infinity sum
- Verified that ECDH_compute_key preserves LibreSSL 2.5.4 check order: outLength > INT_MAX (ERR_LIB_ECDH/ERR_R_MALLOC_FAILURE), missing private key (ECDH_R_NO_PRIVATE_VALUE), missing group (ERR_R_PASSED_NULL_PARAMETER + ERR_R_MALLOC_FAILURE), peer point at infinity (EC_R_POINT_AT_INFINITY + ECDH_R_POINT_ARITHMETIC_FAILURE), key truncation, and KDF failure
- Verified docs/dev/debt/changes/fix-libressl-ec-error-queue.md accurately documents intentional deviations and cross-library behavior with libSceLibreSsl3
- Verified LP64/LLP64 type safety across size_t, unsigned int, and int in all modified functions and test cases
Looks Good To Me
What
Resubmission of #25114, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit
4c70af63162; the reviews and the discussion are on #25114.The EC, ECDSA and ECDH exports of
libSceLibreSsl(src/Ec.cpp) returned their failure values with an empty error queue: the file did not queue a single error. LibreSSL 2.5.4 queues a reason for each of these failures, and the debt file said so ("queue no error code", "return null without queuingEC_R_UNKNOWN_GROUP"). A caller that readsERR_get_errorafter a failed call got 0. This is the EC counterpart of #25035 (RSA).No return value and no output byte changes; only the queue does. Libraries: EC 16, ECDSA 42, ECDH 43 (
err.h); function0xfffas elsewhere in this library.2e2c6120)EC_GROUP_new_by_curve_name,EC_KEY_new_by_curve_nameEC_R_UNKNOWN_GROUPec_curve.cL3255-L3272,ec_key.cL94-L105EC_POINT_point2octEC_R_INVALID_FORMecp_oct.cL210-L215EC_R_BUFFER_TOO_SMALLecp_oct.cL219-L221, L233-L235EC_KEY_generate_keyERR_R_PASSED_NULL_PARAMETERec_key.cL219-L222EC_KEY_set_public_keyERR_R_PASSED_NULL_PARAMETERec_key.cL442-L447 throughEC_POINT_dupEC_KEY_check_keyERR_R_PASSED_NULL_PARAMETERec_key.cL276-L279EC_R_POINT_AT_INFINITY/EC_R_POINT_IS_NOT_ON_CURVE/EC_R_INVALID_PRIVATE_KEYECDSA_signERR_R_PASSED_NULL_PARAMETERecs_ossl.cL220-L223ECDSA_verifyECDSA_R_MISSING_PARAMETERSecs_ossl.cL323-L327ECDSA_R_BAD_SIGNATUREEC_R_POINT_AT_INFINITY, then ECDSAERR_R_EC_LIBecp_smpl.cL535-L538,ecs_ossl.cL399-L403ECDH_compute_keyINT_MAXERR_R_MALLOC_FAILUREech_key.cL107-L111ECDH_R_NO_PRIVATE_VALUEERR_R_PASSED_NULL_PARAMETER, then ECDHERR_R_MALLOC_FAILUREEC_R_POINT_AT_INFINITY, thenECDH_R_POINT_ARITHMETIC_FAILUREecp_smpl.cL535-L538,ech_key.cL140-L144ECDH_R_KEY_TRUNCATION/ECDH_R_KDF_FAILEDErrors already in the queue before the call stay in front of the new ones.
Left as it was (written in the debt fragment):
EC_POINT_newandEC_POINT_oct2point: fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466 works on the decoding errors of these two, on another implementation of the file, so this PR does not touch them;ECDSA_verifystill returns -1 with an empty queue (the source queues ASN.1 errors);BNand arithmetic failures still throw;ECDH_compute_key: -1 with an empty queue, because the source's answer depends on the curve methods of its build;OPENSSL_BN_ASM_MONTclears the queue whenEC_GROUP_new_by_curve_nameloads a non-NIST prime curve (ec_cvt.c); whether the module is built that way is not known, and the port keeps the queue.Effect on
libSceLibreSsl3. That library forwards ten of these exports to this one, so its callers now see these errors too, with the 2.5.4 library numbers (42 and 43) where 4.0.0 queues everything underERR_LIB_EC. Before this PR they saw an empty queue. The debt fragment records it.Tested
Windows 11, MinGW GCC 15.2. Not tested on a console.
guest_libressl_ec_error_queue(new file). Each call checks the return value and the whole queue in order, and next to every failure a call that succeeds checks that the queue stays empty: curve names; point encoding in the three forms, at infinity and with buffers one byte short; key generation,EC_KEY_set_public_keyandEC_KEY_check_keyon keys missing each part, with a public key at infinity, off the curve and belonging to another private key; signing without a private key; verification with r and s at each bound; ECDH without a private key, without a group, with a null or infinite peer, one byte short, and with a KDF that fails. Several cases also run with an error queued beforehand.ECDSA_verifyneeds a signature built for it: with the RFC 6979 P-256 test key, r = -m·d⁻¹ mod n makes u1·G + u2·Q vanish for any s. A script computes r and checks the sum for three values of s; the test uses those three.Ec.cppfrommainthe new test fails at its first expected error; with the change it passes.guest_libressl_ec,guest_libressl_ec_keys,guest_libressl_ec_point_mul, and on thelibSceLibreSsl3side, which forwards to this code,guest_libressl3_key_der,pem_keys,pkey_context,pkey_context_new_id,ecdsa,ecdsa_sig_lifetime,ec_group,ec_key_asn1_flag,ec_parametersandec_public_key.Ec.cpp, each rebuilt and run on its own, all make the test fail: each queued error removed, replaced by a neighbouring reason or queued under another library, the order of the two-error pairs swapped, and the three guards (positive NID, non-null point, same curve) removed.python tools/check_conventions.py --base origin/main,python tools/debt_fold.py --checkandpython core/libs/tests/test_public_headers.py --audit-onlypass.Not verified. The expected queues come from reading the 2.5.4 source, not from running a LibreSSL 2.5.4 binary or a console.
Overlap (
python tools/pr_overlap.py --branch fix/libressl-ec-error-queue):mainand sharecore/libs/prx/libSceLibreSsl/CMakeLists.txt(feat(libSceLibreSsl): implement EC_KEY_get0_private_key and EC_KEY_set_private_key #11146, fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466, feat(libSceLibreSsl): implement d2i_X509 and X509_free #13266, feat(libSceLibreSsl): implement X509_STORE_add_cert #13285, feat(libSceLibreSsl): implement i2d_X509_PUBKEY #13546, feat(libSceLibreSsl): implement X509_INFO_free #13547, feat(libSceLibreSsl): implement X509_get_ext_d2i #13877, feat(libSceLibreSsl): decode X509 public keys and load PEM certificate stores #21701, feat(libSceLibreSsl3): decode X509 certificates from BIO #23573, refactor: split large emulator libraries into small-size libraries #24322, refactor: split Icu and libc sources into small-size libraries #24910, refactor: split more prx libraries (Pad, NetCtl, Ult, NpManager, SystemService, others) into small-size libraries #24917); this PR adds one test block to that file.Ec.cpp. Both date from October and carry another implementation of that file, written before the one now onmain(their diff addsEc.cppas a new 559-line file). fix(libSceLibreSsl): decode compressed 224-bit EC points and report errors #11466 queues the decoding errors ofEC_POINT_oct2pointand the errors ofEC_POINT_new; this PR leaves those two functions alone.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)