feat(libSceLibreSsl): implement X509_NAME_get_entry and X509_NAME_ENTRY_get_data #10477

Closed
alvaroelpob wants to merge 5 commits from upstream-pr/10477 into main
alvaroelpob commented 2026-10-24 02:42:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T02:42:20Z.


What

Implements X509_NAME_get_entry and X509_NAME_ENTRY_get_data in libSceLibreSsl, which threw and were declared without parameters.

The module is LibreSSL 2.5.4 (firmware 13.40 measurements in #8981). Signatures, layouts and results follow that release's x509.h, x509name.c and stack.c:

Export Behaviour
X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME*, int loc) null for a null name, a negative loc, a null entry stack (sk_num is -1) or loc >= num; otherwise entries->data[loc]
ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY*) null for a null entry, otherwise value

The layouts are 40 bytes for X509_NAME (entries at 0), 24 for X509_NAME_ENTRY (object, value, set, size) and 32 for _STACK (num, data, sorted, num_alloc, comp). They were checked with static_asserts and against offsetof from the 2.5.4 headers compiled on x86-64. A positive entry count with a null entry array, which LibreSSL dereferences, throws. No export of this module creates a name yet, so for now only names built by the caller reach these functions.

The 2.5.4 _STACK layout is main's LibreSslStack from #10373. This PR reads it through that struct and changes none of the sk_* exports.

The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 355.

Tested

Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with BUILD_TESTING=ON on main db6af9e0f. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its guest_libressl_x509_name test and check_conventions.py run on its own.

  • New guest_libressl_x509_name test. X509_NAME_get_entry returns null for a null name, a null entry stack, indexes -1, INT_MIN, INT_MAX and num, and an empty stack. It returns the first and second entries of a two-entry stack, and a null slot as null. A null entry array throws, unless the index is out of range. X509_NAME_ENTRY_get_data returns null for a null entry or a null value, and otherwise the value, whatever object and set hold.
  • Full ctest -j16 at the last commit: 2005/2006 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • Not tested: Windows, a title.
  • Rebased on main 1e740a23a3 (after #9033), head 448392a96b: the conflicts were only the add_library source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and ctest -j16: 2043/2044 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main e7e3e9c198, head 73b11e79a7, to resolve the conflict from #9529 on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 73b11e79a7 (refactor(libSceLibreSsl): declare the X509_NAME exports in the public header) puts the real signatures and their structs in libSceLibreSsl/include/Api.hpp and drops the test's redeclarations, which public_headers requires since #10706. Full build and ctest -j16: 2202/2203 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main ae7d59258e (after #9949), head aa4fd175d5, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and ctest -j16: 2275/2276 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 88795ed448 (after #10248; head 06e8626898) to resolve the conflicts on the shared debt-file lines; both sides are kept and the count is 335 minus this PR's exports. Full build and ctest -j16: 2383/2384 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main c7b4878fa8 (after #10373, #10376 and #10449), head 0d079a6d82, to resolve the conflicts with main on the shared CMakeLists.txt, Api.hpp and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. The rebase drops this PR's copy of LibreSslStack from Api.hpp, and its two static_asserts in X509Name.cpp, since main now declares the same struct (with comp typed as StackCompare) and asserts its layout in Stack.cpp. Full build and ctest -j16: 2394/2395 pass; agc_driver_multisample_retirement fails the same way on that main, and guest_pthread_start timed out once at 20 s while another full suite shared the machine; run alone with --repeat until-fail:3 it passes 3/3 in about 2 s. check_conventions.py --base upstream/main passes.
  • Rebased on main 474030e584 (after #13562), head 63a6ee75dc, to resolve the conflict on the pending-export count in the debt file; the count is 292 minus this PR's exports. Full build and ctest -j16: 3062/3062 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main cf79276fee (after #13820), head 1fe82b5b65, to resolve the conflict on the pending-export count in the debt file. main still says 292 although #13820 removed two stubs, leaving 290, so the count is now set to the 288 stubs left in Export.cpp. It also restores the PS5 3.20 export table link, b2a77c09cd71c01f34c790cfbe98c751a13262ad, which the previous rebase had written without its zeros. Full build and ctest -j16: 3107/3107 pass (log_file failed once on #10486 and passed on five reruns and a second full run). check_conventions.py --base upstream/main passes.
  • Rebased on main 4939814d79 (after #9970, #10078 and #10488), head 886b309bda, to resolve the conflicts on the shared CMakeLists.txt, Export.cpp, Api.hpp and debt-file lines; both sides are kept. The count is set to the 259 stubs left in Export.cpp. Full build and ctest -j16: 3538/3538 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main 4f41f4c375, head 2417a2f231, to resolve the conflicts on the shared CMakeLists.txt, Export.cpp and debt-file lines; both sides are kept and the debt count is recomputed from Export.cpp. Full build and ctest -j16: 3796/3800 pass; guest_sce_net, guest_poll, guest_select_wait and guest_memory failed under that load, pass when run alone, and main 4f41f4c375 passes all 3799 with -j16 on the same machine. check_conventions.py --base upstream/main passes.

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: #9446, #9571, #10395, #10418, #10448, #10450
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4991858853 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10477). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T02:42:20Z. --- ### What Implements `X509_NAME_get_entry` and `X509_NAME_ENTRY_get_data` in libSceLibreSsl, which threw and were declared without parameters. The module is LibreSSL 2.5.4 ([firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, layouts and results follow that release's [`x509.h`, `x509name.c`](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/x509) and [`stack.c`](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/stack/stack.c): | Export | Behaviour | |---|---| | `X509_NAME_ENTRY* X509_NAME_get_entry(X509_NAME*, int loc)` | null for a null name, a negative `loc`, a null entry stack (`sk_num` is -1) or `loc >= num`; otherwise `entries->data[loc]` | | `ASN1_STRING* X509_NAME_ENTRY_get_data(X509_NAME_ENTRY*)` | null for a null entry, otherwise `value` | The layouts are 40 bytes for `X509_NAME` (`entries` at 0), 24 for `X509_NAME_ENTRY` (`object`, `value`, `set`, `size`) and 32 for `_STACK` (`num`, `data`, `sorted`, `num_alloc`, `comp`). They were checked with `static_assert`s and against `offsetof` from the 2.5.4 headers compiled on x86-64. A positive entry count with a null entry array, which LibreSSL dereferences, throws. No export of this module creates a name yet, so for now only names built by the caller reach these functions. The 2.5.4 `_STACK` layout is `main`'s `LibreSslStack` from #10373. This PR reads it through that struct and changes none of the `sk_*` exports. The debt entry records the source and what is unverified, and the pending-export count drops from 357 to 355. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with `BUILD_TESTING=ON` on `main` db6af9e0f. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its `guest_libressl_x509_name` test and `check_conventions.py` run on its own. - New `guest_libressl_x509_name` test. `X509_NAME_get_entry` returns null for a null name, a null entry stack, indexes -1, `INT_MIN`, `INT_MAX` and `num`, and an empty stack. It returns the first and second entries of a two-entry stack, and a null slot as null. A null entry array throws, unless the index is out of range. `X509_NAME_ENTRY_get_data` returns null for a null entry or a null value, and otherwise the value, whatever `object` and `set` hold. - Full `ctest -j16` at the last commit: 2005/2006 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - Not tested: Windows, a title. - Rebased on `main` 1e740a23a3 (after #9033), head 448392a96b: the conflicts were only the `add_library` source list, the end of the test block, the pending-export count and the last debt entry; both sides are kept and the count is 357 minus this PR's exports. Full build and `ctest -j16`: 2043/2044 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` e7e3e9c198, head 73b11e79a7, to resolve the conflict from #9529 on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 353 minus this PR's exports. 73b11e79a7 (`refactor(libSceLibreSsl): declare the X509_NAME exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl/include/Api.hpp` and drops the test's redeclarations, which `public_headers` requires since #10706. Full build and `ctest -j16`: 2202/2203 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` ae7d59258e (after #9949), head aa4fd175d5, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 342 minus this PR's exports. Full build and `ctest -j16`: 2275/2276 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 88795ed448 (after #10248; head 06e8626898) to resolve the conflicts on the shared debt-file lines; both sides are kept and the count is 335 minus this PR's exports. Full build and `ctest -j16`: 2383/2384 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` c7b4878fa8 (after #10373, #10376 and #10449), head 0d079a6d82, to resolve the conflicts with `main` on the shared `CMakeLists.txt`, `Api.hpp` and debt-file lines; both sides are kept and the count is 319 minus this PR's exports. The rebase drops this PR's copy of `LibreSslStack` from `Api.hpp`, and its two `static_assert`s in `X509Name.cpp`, since `main` now declares the same struct (with `comp` typed as `StackCompare`) and asserts its layout in `Stack.cpp`. Full build and `ctest -j16`: 2394/2395 pass; `agc_driver_multisample_retirement` fails the same way on that `main`, and `guest_pthread_start` timed out once at 20 s while another full suite shared the machine; run alone with `--repeat until-fail:3` it passes 3/3 in about 2 s. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 474030e584 (after #13562), head 63a6ee75dc, to resolve the conflict on the pending-export count in the debt file; the count is 292 minus this PR's exports. Full build and `ctest -j16`: 3062/3062 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` cf79276fee (after #13820), head 1fe82b5b65, to resolve the conflict on the pending-export count in the debt file. `main` still says 292 although #13820 removed two stubs, leaving 290, so the count is now set to the 288 stubs left in `Export.cpp`. It also restores the PS5 3.20 export table link, `b2a77c09cd71c01f34c790cfbe98c751a13262ad`, which the previous rebase had written without its zeros. Full build and `ctest -j16`: 3107/3107 pass (`log_file` failed once on #10486 and passed on five reruns and a second full run). `check_conventions.py --base upstream/main` passes. - Rebased on `main` 4939814d79 (after #9970, #10078 and #10488), head 886b309bda, to resolve the conflicts on the shared `CMakeLists.txt`, `Export.cpp`, `Api.hpp` and debt-file lines; both sides are kept. The count is set to the 259 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3538/3538 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 4f41f4c375, head 2417a2f231, to resolve the conflicts on the shared `CMakeLists.txt`, `Export.cpp` and debt-file lines; both sides are kept and the debt count is recomputed from `Export.cpp`. Full build and `ctest -j16`: 3796/3800 pass; `guest_sce_net`, `guest_poll`, `guest_select_wait` and `guest_memory` failed under that load, pass when run alone, and `main` 4f41f4c375 passes all 3799 with `-j16` on the same machine. `check_conventions.py --base upstream/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9446, #9571, #10395, #10418, #10448, #10450 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 02:44:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T02:44:14Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636466396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10477#pullrequestreview-5636466396). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T02:44:14Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-24 16:00:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T16:00:00Z.

Review: APPROVED


Reviewed both X509_NAME accessors against the cited LibreSSL 2.5.4 layouts and stack behavior. The entry-count/data-array checks preserve the null/out-of-range behavior described, and the data getter returns only the entry's value field; the focused tests cover boundary and null-slot cases. The current head merges cleanly with upstream main; conventions and diff checks pass. I compiled and ran GuestLibreSslX509Name.cpp with X509Name.cpp directly using GCC 12.2.0; it passed. The broader Linux suite is author-reported; hosted product jobs are skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638873978 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10477#pullrequestreview-5638873978). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T16:00:00Z. **Review:** APPROVED --- Reviewed both X509_NAME accessors against the cited LibreSSL 2.5.4 layouts and stack behavior. The entry-count/data-array checks preserve the null/out-of-range behavior described, and the data getter returns only the entry's value field; the focused tests cover boundary and null-slot cases. The current head merges cleanly with upstream main; conventions and diff checks pass. I compiled and ran `GuestLibreSslX509Name.cpp` with `X509Name.cpp` directly using GCC 12.2.0; it passed. The broader Linux suite is author-reported; hosted product jobs are skipped.
ahmadmuj commented 2026-10-25 18:06:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T18:06:23Z.

Review: APPROVED


Reviewed head d63afe313c, merged locally onto main 7a25f87620. Linux, GCC 13.3, Release.

What I ran:

  • guest_libressl_x509_name on the merged tree: pass.
  • Mutation controls, one at a time on X509Name.cpp: main's stub bodies, num < loc instead of num <= loc, no loc < 0 check, and entry->object instead of entry->value. The test fails on each.
  • Layout probe against LibreSSL 2.5.4 built from the release tarball (sha256 107a5b52..., matches the published SHA256): every field of X509_NAME, X509_NAME_ENTRY and _STACK has the same offset and size as LibreSslX509Name, LibreSslX509NameEntry and LibreSslStack (40/24/32 bytes). OPENSSL_NO_BUFFER only switches bytes between two pointer types.
  • Differential: I dlopened the merged libSceLibreSsl.prx and passed real 2.5.4 X509_NAME* values straight to both exports. I compared them with 2.5.4's own calls for loc in INT_MIN, -2, -1, 0..count+1, INT_MAX, and get_data on every entry. The names were a null name, an empty name, API-built names (multi-valued RDNs, 40 entries, 38 after deletes) and subjects/issuers parsed from DER certs with 1, 3, 6 (multi-valued) and 11 entries. 363 comparisons, 0 mismatches.
  • num > 0 with a null data array: 2.5.4 segfaults for loc 0..num-1 and returns NULL outside that range. This PR throws for the same loc values and returns NULL for the rest. That matches the debt entry.

Sources: 2.5.4 x509name.c X509_NAME_get_entry / X509_NAME_ENTRY_get_data, stack.c sk_num / sk_value, x509.h, stack.h.

LGTM. One heads-up: the branch now conflicts with main in docs/dev/debt/libSceLibreSsl.md only. Main reworded the MD4..SHA512 entry next to your count line, so CI needs a merge first.

Not checked: the console, and whether the module really is 2.5.4. I relied on the #8981 measurement for that, as the debt entry does.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644554801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10477#pullrequestreview-5644554801). Originally posted by [ahmadmuj](https://github.com/ahmadmuj) on 2026-10-25T18:06:23Z. **Review:** APPROVED --- Reviewed head `d63afe313c`, merged locally onto main `7a25f87620`. Linux, GCC 13.3, Release. What I ran: - `guest_libressl_x509_name` on the merged tree: pass. - Mutation controls, one at a time on `X509Name.cpp`: main's stub bodies, `num < loc` instead of `num <= loc`, no `loc < 0` check, and `entry->object` instead of `entry->value`. The test fails on each. - Layout probe against LibreSSL 2.5.4 built from the release tarball (sha256 `107a5b52...`, matches the published SHA256): every field of `X509_NAME`, `X509_NAME_ENTRY` and `_STACK` has the same offset and size as `LibreSslX509Name`, `LibreSslX509NameEntry` and `LibreSslStack` (40/24/32 bytes). `OPENSSL_NO_BUFFER` only switches `bytes` between two pointer types. - Differential: I dlopened the merged `libSceLibreSsl.prx` and passed real 2.5.4 `X509_NAME*` values straight to both exports. I compared them with 2.5.4's own calls for `loc` in `INT_MIN, -2, -1, 0..count+1, INT_MAX`, and `get_data` on every entry. The names were a null name, an empty name, API-built names (multi-valued RDNs, 40 entries, 38 after deletes) and subjects/issuers parsed from DER certs with 1, 3, 6 (multi-valued) and 11 entries. 363 comparisons, 0 mismatches. - `num > 0` with a null `data` array: 2.5.4 segfaults for `loc` 0..num-1 and returns NULL outside that range. This PR throws for the same `loc` values and returns NULL for the rest. That matches the debt entry. Sources: 2.5.4 `x509name.c` `X509_NAME_get_entry` / `X509_NAME_ENTRY_get_data`, `stack.c` `sk_num` / `sk_value`, `x509.h`, `stack.h`. LGTM. One heads-up: the branch now conflicts with main in `docs/dev/debt/libSceLibreSsl.md` only. Main reworded the MD4..SHA512 entry next to your count line, so CI needs a merge first. Not checked: the console, and whether the module really is 2.5.4. I relied on the #8981 measurement for that, as the debt entry does.
MarcZX10 commented 2026-10-29 08:59:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:59:38Z.

Review: CHANGES_REQUESTED


Re-check — changes requested\n\nThe new report is useful: it says the implementation functions were preserved through the merge and the full test suite has the same single known failure as its tested main, with conventions passing. However, the tested integration point is 4c7d275bef; current upstream main is aaccd0ba39, and this PR head is 44 commits behind it.\n\nPlease update onto current main, preserve the implementation and debt-count changes, recount the pending exports against the resulting Export.cpp, and rerun the relevant LibreSSL tests plus conventions on the exact updated head. The earlier approval was for the prior head and does not cover this stale integration point. I did not rerun these checks locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695135725 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10477#pullrequestreview-5695135725). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:59:38Z. **Review:** CHANGES_REQUESTED --- ## Re-check — changes requested\n\nThe new report is useful: it says the implementation functions were preserved through the merge and the full test suite has the same single known failure as its tested main, with conventions passing. However, the tested integration point is 4c7d275bef; current upstream main is aaccd0ba39, and this PR head is 44 commits behind it.\n\nPlease update onto current main, preserve the implementation and debt-count changes, recount the pending exports against the resulting Export.cpp, and rerun the relevant LibreSSL tests plus conventions on the exact updated head. The earlier approval was for the prior head and does not cover this stale integration point. I did not rerun these checks locally.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10477
No description provided.