Skip to content

feat(libSceLibreSsl): implement OBJ_create and free added objects in OBJ_cleanup - #13562

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
JaceTheBlu:feat/libressl-obj-create
Oct 31, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
JaceTheBlu:feat/libressl-obj-create

Conversation

@JaceTheBlu

Copy link
Copy Markdown
Contributor

What

Implements OBJ_create in libSceLibreSsl and makes OBJ_cleanup, until now an empty stub, free what it adds. OBJ_obj2txt (behind i2t_ASN1_OBJECT) now names added objects.

The new src/ObjectCreate.cpp follows LibreSSL 2.5.4 obj_dat.c:

  • OBJ_create parses the dotted text with a port of a2d_ASN1_OBJECT (a_object.c):
    • spaces and dots as separators, empty arcs read as zero, and arcs past 64 bits;
    • the same ASN.1 error codes for each bad input, including an empty text, which LibreSSL reads as a bad first arc;
    • a text with no second arc value, such as 1., adds nothing and queues nothing.
  • Each object takes the next NID from 956 (NUM_NID).
  • The added table is keyed by encoding and by NID, as in OBJ_add_object. The latest object with a given encoding wins.
  • The lookups in ObjectText.cpp follow OBJ_obj2nid and OBJ_nid2ln/OBJ_nid2sn:
    • Added encodings are searched before the built-in table, so an added copy of a built-in OID changes its name.
    • Once the table exists, an unknown NID past the table queues OBJ_R_UNKNOWN_NID; before that, and after OBJ_cleanup, it queues nothing.
  • OBJ_cleanup drops every added object and the table, but keeps the NID counter.

The OBJ_cleanup part of the silent-stub entry and the i2t_ASN1_OBJECT entry are updated, and there is a new entry in docs/dev/debt/libSceLibreSsl.md. The pending count goes from 293 to 292.

Remaining differences from LibreSSL:

  • Added objects live in host memory, so an allocation failure throws instead of queuing ERR_R_MALLOC_FAILURE.
  • OBJ_cleanup is never deferred. check_defer only fires for ciphers or digests with an added NID, and no export registers one.
  • Name lookups of added objects (OBJ_sn2nid, OBJ_ln2nid) are not kept, since no export reads them yet.
  • A null OID text throws where LibreSSL faults.

Tested

Debian container, GCC 14.2, full Release build of head 50527ff1d6: ctest -R 'libressl|crypto_memcmp' passes 34 of 34. tools/check_test_registration.py and python3 tools/check_conventions.py --base upstream/main pass.

  • guest_libressl_object_text checks:

    • each parse error code, an empty text and a text without a second arc value;
    • NID numbering, including after OBJ_cleanup;
    • long-name, short-name and dotted fallback;
    • an added copy of commonName overriding the table;
    • an arc past 64 bits, and empty arcs;
    • the OBJ_R_UNKNOWN_NID queue before and after OBJ_cleanup;
    • that OBJ_cleanup restores built-in names.
  • guest_libressl_oracle (ANYPS5_LIBRESSL_ORACLE) now also runs 20,000 rounds of OBJ_create on both implementations, with an occasional OBJ_cleanup on both. Each round uses:

    • random dotted or spaced texts, some with huge arcs or a damaged character;
    • random or null names.

    After each call it compares the result and the error queue. It then compares i2t_ASN1_OBJECT, with random buffer sizes, on four objects drawn from built-in and created encodings, some with a preset NID around the end of the table. The 20,000 rounds show no difference. The only differences the oracle reports are the 6 AES_set_*_key cases already described in the debt file.

Not tested on Windows, on a title or on a console.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

…OBJ_cleanup

Port OBJ_create and a2d_ASN1_OBJECT from LibreSSL 2.5.4, keep the added
objects by encoding and NID, and look them up in OBJ_obj2txt before the
built-in table. OBJ_cleanup now drops them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9448 core/libs/prx/libSceLibreSsl/Export.cpp L732-770
docs/dev/debt/libSceLibreSsl.md L10
PR 9571 docs/dev/debt/libSceLibreSsl.md L10
PR 10078 docs/dev/debt/libSceLibreSsl.md L10
PR 10395 docs/dev/debt/libSceLibreSsl.md L10
PR 10448 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10477 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10478 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10481 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10482 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10483 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10485 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10486 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10488 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10834 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 10878 docs/dev/debt/libSceLibreSsl.md L10
PR 11003 docs/dev/debt/libSceLibreSsl.md L10
PR 11466 docs/dev/debt/libSceLibreSsl.md L10, L37-38
PR 12729 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 12730 docs/dev/debt/libSceLibreSsl.md L10, L27-28
PR 12844 docs/dev/debt/libSceLibreSsl.md L10

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.

Pull request Shared files not compared
PR 9446 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 10418 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10508 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10570 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 10571 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11128 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11129 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11138 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11143 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11146 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11151 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11174 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11175 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11176 core/libs/prx/libSceLibreSsl/CMakeLists.txt
core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md
PR 11553 docs/dev/debt/libSceLibreSsl.md
PR 11662 core/libs/prx/libSceLibreSsl/Export.cpp
docs/dev/debt/libSceLibreSsl.md
PR 12928 core/libs/prx/libSceLibreSsl/Export.cpp
core/libs/prx/libSceLibreSsl/include/Api.hpp
docs/dev/debt/libSceLibreSsl.md

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Progress report (b852c46 → 980a325)

📈 System libraries: 26.35% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceLibreSsl OBJ_create_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl 96/401 (23.94%) 97/401 (24.19%) +0.25%

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@JaceTheBlu Thanks, this matches LibreSSL 2.5.4's a2d_ASN1_OBJECT, OBJ_add_object and OBJ_cleanup as far as we can read them, and the oracle run against the 2.5.4 build is good evidence. Three small things:

  1. OBJ_create stores added.get() in byData and byNid before objects.push_back has taken ownership. If a later map insertion or the vector growth throws, the unique_ptr frees the object while an index still points at it; with allocation-failure injection, failure points 9 and 10 leave index entries with no owning object. Taking ownership first (or reserving, then publishing the indexes last, and undoing a replaced encoding on failure) keeps the table consistent, and a small allocation-failure test that retries lookup, creation and cleanup would pin it.
  2. src/ObjectCreate.cpp is committed with mode 100755, while the other sources in that folder are 100644 (git update-index --chmod=-x core/libs/prx/libSceLibreSsl/src/ObjectCreate.cpp).
  3. ObjectCreate.cpp ports LibreSSL's a2d_ASN1_OBJECT but starts directly with includes. Please keep the original copyright and licence notice from the LibreSSL source (and the 2.5.4 revision it was taken from) at the top of the file, as the shadPS4-derived files in the tree do with their SPDX header.

@blawesom

Copy link
Copy Markdown
Contributor

Verified 50527ff1d on Linux x86-64 (AMD Ryzen 7 9800X3D, CachyOS kernel 6.2.10, GCC 16.2.1, Release, BUILD_TESTING=ON).

  • Build: guest_libressl_object_text_tests and guest_libressl_object_allocation_tests compile and link clean on the PR head.
  • Tests: guest_libressl_object_text and guest_libressl_object_allocation pass (3 consecutive runs for flakiness); all 29 ^guest_libressl_ tests pass.
  • Oracle: guest_libressl_oracle is not configured in this build (ANYPS5_LIBRESSL_ORACLE=OFF); not run — no downloads performed.
  • Code reading: OBJ_create ports LibreSSL 2.5.4 a2d_ASN1_OBJECT/OBJ_add_object faithfully, and the debt doc entry for OBJ_create/OBJ_cleanup is updated.

Review items from @oneandonlydean (all three still open — head is unchanged since 50527ff1d, pushed before the review):

  1. Ownership order: byData[...] and byNid[...] are populated with added.get() before objects.push_back(std::move(added)); if a map insertion throws after the first, or the vector growth throws, the indexes hold dangling pointers. Not yet fixed and no allocation-failure retry test added.
  2. File mode: src/ObjectCreate.cpp is still 100755 (git ls-files -s), not 100644.
  3. Licence header: ObjectCreate.cpp still starts with includes; the original LibreSSL copyright/licence notice for the ported a2d_ASN1_OBJECT is still missing.

Not approving — awaiting the maintainer's three requested changes.

…J_create throws

Take ownership before publishing an object, roll back the NID index if
the encoding index cannot grow, and test every allocation failure. Keep
the LibreSSL copyright notice of the ported code and drop the
executable bit of ObjectCreate.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JaceTheBlu

Copy link
Copy Markdown
Contributor Author

@oneandonlydean Thanks, all three are addressed in 980a32590b.

  1. Ownership. OBJ_create now reserves the slot in objects first. It then indexes the NID, then the encoding, and rolls the NID index back if the encoding index cannot grow. The objects.push_back that takes ownership can no longer throw. A replaced encoding is only overwritten once nothing else can fail, so a failed call leaves it pointing at the previous object. guest_libressl_object_allocation now fails each allocation of an OBJ_create that replaces an existing encoding in turn. After each failure it checks:

    • that std::bad_alloc escapes;
    • that the replaced encoding still names the old object;
    • that a later OBJ_create and its lookup work;
    • that OBJ_cleanup frees everything, with no tracked allocation left.

    It passes, as do guest_libressl_object_text and the oracle's 20,000 OBJ_create rounds (0 differences).

  2. Mode. src/ObjectCreate.cpp is now 100644.

  3. Notice. The file now starts with the sources and the LibreSSL 2.5.4 revision it ports: a_object.c v1.29 and obj_dat.c v1.39 at openbsd 2e2c6120. The Eric Young copyright and licence notice follows, unchanged.

The same notice was missing from my other LibreSSL PRs, so #13266, #13546, #13547 and #13285 now carry the matching headers: the OpenSSL licence for the tasn_*.c and x_algor.c/x_exten.c/x509_vpm.c code, and the Eric Young notice for the rest. #13285 also had four files at 100755, now 100644. The stacked branches merged the #13266 update rather than being rewritten, and each still passes the 38 LibreSSL tests.

@adriadam10 adriadam10 self-assigned this Oct 31, 2026
@adriadam10
adriadam10 merged commit de5c21f into boykopovar:main Oct 31, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the three points from review against 980a32590b: the OBJ_create publish order is exception-safe (slot reserved first, NID index rolled back if the encoding index fails, replaced encoding overwritten last) and the allocation-failure test pins it, the file mode is 100644, and the LibreSSL 2.5.4 notice is at the top of ObjectCreate.cpp. Parse errors, NID numbering, latest-encoding-wins and the OBJ_R_UNKNOWN_NID behaviour before and after OBJ_cleanup match a_object.c / obj_dat.c; debt entries updated; merged.

ahmadmuj pushed a commit to ahmadmuj/AnyPS5 that referenced this pull request Oct 31, 2026
docs/dev/debt/libSceLibreSsl.md: the pending-exports line counts 286 named callable exports, the NotImplemented_nid_no_patch calls left in the merged Export.cpp after boykopovar#13562 implemented OBJ_create.
oneandonlydean pushed a commit that referenced this pull request Nov 6, 2026
docs/dev/debt/libSceLibreSsl.md: the pending-exports line counts 281 named callable exports, the NotImplemented_nid_no_patch calls left in the merged Export.cpp after #13562 implemented OBJ_create.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants