feat(libressl3): retain EVP and EC key references #11165
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11165"
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 atharvjairath on 2026-10-25T20:20:20Z.
What
EVP_PKEY_up_refandEC_KEY_up_refcurrently throw. They now increment the caller's key reference count and return whether the resulting count exceeds one, preserving all other object bytes. Atomic updates prevent lost retains when several threads share a key. The public umbrella exposes one canonical declaration and layout for each API; tests have no duplicate declarations.Signatures, object layouts and return behavior follow pinned LibreSSL 4.0.0 commit
ce488b78e0bd994780569df718596b9776ff681a: p_lib.c, evp_local.h, ec_key.c, ec_local.h and crypto_lock.c. The EVP/EC objects have 32/64-byte LP64 layouts and signed 32-bit counters at offsets 4/48. This implementation uses C++ atomic operations instead of upstream's internal mutex. Null keys and signed-count overflow, which are undefined upstream, throw without mutation.The unchanged progress scanner reports 3 → 5 completed exports out of 87: 3.45% → 5.75% for libSceLibreSsl3, with 81 pending exports. The merged
d2i_ASN1_INTEGERremains scanner-incomplete outside the pending block; its upstream implementation is not counted as one of our two completed exports. This is two more implemented exports, not a game-compatibility measurement. No other pending export is converted to a success stub.Independent physical-console verification remains absent. The source-based layouts and limited retain/release interoperability now have the attributed firmware-module evidence below; broader compatibility remains unverified and is recorded in the existing debt file. The module has no key constructors/destructors yet; these functions operate on caller-owned objects. Future releases must synchronize with the same counters. This PR introduces no third-party dependency or copied upstream source.
The exact overlap CLI scan and manual review of the 12 current external shared-file peers found no duplicate of either function. The peers add ERR, version, ASN.1, DH/DSA/RSA getters, X509 accessors, object comparison and digest APIs. Their source/API/CMake/debt changes are separate; no unmerged peer implementation was imported into this branch. RSA retain is excluded to avoid introducing a competing RSA layout alongside #10490.
Landing order: #10948 has merged. This PR is rebased onto main
c980e6ef338b8a5e59546f922b174e4d9c6ad493with its ASN.1 decoder, canonical declarations, libc link, fixture and debt preserved. CMake, API and debt conflicts are resolved; the retain implementation, layouts and fixture are byte-identical to the prior head. No open prerequisite remains. The accepted remaining order is #11165 before #10960; #9448 also precedes #10960 and is not a prerequisite of this PR. Neither unmerged branch was imported here.Tested
Exact head:
5255577954c2ff77aab20e4f715edf16f2c40c4a; tree:8fa5d4b7410916562ae4f7d465ed72271413646a; parent and tested base:c980e6ef338b8a5e59546f922b174e4d9c6ad493. Recoverybackup/pr-11165-before-asn1-integration-20261027-0328preserves prior remote220d1eb65d7f40092e17398b4539d74c6cde8b61. Author and committer:atharvjairath <[email protected]>.220d1eb65dfailed at each named unimplemented export on Linux and Windows and passed after restoring the candidate. They were not rerun in this rebase; the retain implementation and fixture remain byte-identical.-fno-sanitize-recover=alland execution passed forKey.cppand its fixture. The other library implementations are not sanitizer-instrumented by that check.-Werrorumbrella compilation (included twice) pass. The export-count increase is verified against the unchanged main module using the same scanner.The Wine matrix retains
APS5_NO_WRITE_WATCH=1only for the existing runtime and legacy ASN.1 conversion tests. Their earlier exact-base controls and failure logs are historical and were not rerun here. The allocator, UI, retain and new LibreSSL3 ASN.1 tests use defaults. The UI fixture failed with0xc000001din the rebuilt libc; a main LibreSSL control without our retain implementation reproduced the same failure using the identical current libc and unchanged UI executable. No new switch, assertion change or production workaround was added. The failed matrix and control logs are retained in/private/tmp/anyps5-monitor-20261026-2020; the retain and new ASN.1 tests passed on both platforms. Native/default Windows write watching, native Windows, the full project, commercial titles and PS5 hardware remain unvalidated here. Full product CI needs maintainer dispatch.Attributed contributor evidence (not independently reproduced here):
libSceLibreSsl3.sprxnatively on a PC, using unchangedKey.cpp/Key.hppfrom220d1eb65don module-created objects. Their allocations and counters match the 32/64-byte layouts and offsets 4/48. Selected signed counts fromINT32_MINthroughINT32_MAX-1matched return values, new counts and unchanged surrounding bytes. Two candidate retains followed by the module's own releases freed each object only on the third release. Null keys and concurrent retains were not tested in that report; this is neither physical-console validation nor general lifetime compatibility.INT32_MAX, the firmware module wraps toINT32_MINand returns 0; this implementation throws without mutation. That unsupported overflow path remains explicit. The report includes controls for wrong counter offsets, return thresholds and removal of the overflow check.77ba69041c5e, #10960010087af4057, this exact220d1eb65d7fand #9448b2583e3cf11con frozen mainae7d59258ea7: 8/8 focused Release and 8/8 ASAN tests, including ASN.1, key references and a 19-NID EVP consumer in both library load orders (3,824 cases per order). These are attributed component results with qualified existing core artifacts and pinned source-built mbedcrypto, not tests of whole current main, Windows or physical-console compatibility. Those unmerged compositions were not imported here and the report is not an approval.Focused reproduction
Save this harness outside the checkout. Put the repository-pinned ZArchive, zstd and mbedTLS sources under its
3rdparty/directory, including mbedTLS's framework submodule. The mbedTLS pin is068ff080b369adfac81509f9b57b2afabaf82dc5.Configure with
cmake -S <harness> -B <build> -G Ninja -DANYPS5_SOURCE_ROOT=<checkout> -DCMAKE_BUILD_TYPE=Release, build, and runctest --test-dir <build> --output-on-failure --timeout 30. On a native x86-64 Linux host no emulator is needed; the reported Apple Silicon run setsCMAKE_CROSSCOMPILING_EMULATORto a native ARM QEMU 11.0.3qemu-x86_64. Windows uses WinLibs CMake/Ninja/GCC under Wine, serial-j1compilation, and a host CTest manifest launching all actual PE tests through QEMU/Wine. SetWINELOADERNOEXEC=1,WINEPREFIXand DLL paths for libc, both LibreSSL libraries and compiler runtimes. Apply the documented Wine setting only toguest_libressl_runtimeandguest_libressl_asn1.For the isolated sanitizer check, compile
core/libs/prx/libSceLibreSsl3/src/Key.cppandcore/libs/tests/GuestLibreSsl3KeyReference.cppwith-std=c++20 -O2 -g -pthread -fsanitize=undefined -fno-sanitize-recover=all -Icore/libs, then run the resulting executable. The fixture acceptsevporecto isolate each negative control.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 MarcZX10 on 2026-10-25T20:29:47Z.
Review: COMMENTED
Reviewed exact head
220d1eb65d7f40092e17398b4539d74c6cde8b61.The implementation matches the pinned LibreSSL retain semantics for positive and non-positive counts: it atomically increments and returns whether the new count exceeds one. It detects signed overflow before mutation, and the focused fixture checks both documented layouts/offsets, unchanged neighboring bytes, concurrent updates, return values, and null/error behavior. The technical-debt entry clearly states the unverified console layout and future release synchronization requirement.
Checks:
git diff --check upstream/main...HEADpasses; three-way merge with currentmainis clean; eligibility, conventions, intake, labels and report checks pass. Product build jobs are skipped by policy. The Linux/Windows focused suites and Linux UBSan results in the description are author-reported; I did not rerun the extensive dependency harness locally.