feat(libSceLibreSsl3): implement ASN1_STRING_get0_data and ASN1_INTEGER_free #10452

Merged
alvaroelpob merged 6 commits from upstream-pr/10452 into main 2026-11-05 22:20:36 +00:00
alvaroelpob commented 2026-10-24 01:07:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alvaroelpob on 2026-10-24T01:07:33Z.


What

Implements ASN1_STRING_get0_data and ASN1_INTEGER_free in libSceLibreSsl3, which threw and were declared without parameters.

The module is LibreSSL 4.0.0 (OpenSSL_version(0) and the image string in the firmware 13.40 measurements in #8981). Signatures, the ASN1_STRING layout and the results follow that release's asn1.h, a_string.c, a_int.c and tasn_fre.c. asn1_string_st is still public there.

Export Behaviour
const unsigned char* ASN1_STRING_get0_data(const ASN1_STRING*) data
void ASN1_INTEGER_free(ASN1_INTEGER*) nothing for null. Otherwise, as ASN1_item_free with ASN1_INTEGER_it reaches ASN1_STRING_free, it zeroes and frees data (freezero) unless ASN1_STRING_FLAG_NDEF (0x10) is set, then frees the string

The layout is main's 24-byte Asn1String (length, type, data at 8, flags at 16), which libSceLibreSsl declares and asserts and the libSceLibreSsl3 header includes since #10948. Memory is released through the guest free, as the module would through libc. The item free path takes the type from ASN1_INTEGER_it, not from the object, so a string of any type is freed the same way.

These throw:

  • a null string in ASN1_STRING_get0_data, which LibreSSL dereferences;
  • a negative length with non-null data in ASN1_INTEGER_free, which freezero would take as a huge size_t.

No export of this module creates a string yet, so for now only strings built by the caller reach these functions.

The debt entry records the source and what is unverified. The pending-export count drops from 84 to 82, and both names join the list of exclusions.

Tested

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

  • New guest_libressl3_asn1_string test. ASN1_STRING_get0_data returns the stored pointer, including null data and the NDEF flag, and a null string throws. ASN1_INTEGER_free is checked on null and on positive, negative, empty and other-typed strings from the guest heap. An NDEF string leaves its data intact, and that data can then be freed by the caller. A negative length with data throws and frees nothing, and the same string is freed once the length is corrected. A negative length with null data frees only the string. On main the first call throws.
  • Full ctest -j16 at the last commit: 2003/2004 pass. agc_driver_multisample_retirement fails the same way on main on this machine.
  • Not tested: Windows, a title.
  • Rebased on main e7e3e9c198, head 75ed618a28. The branch still merged cleanly, but after #10706 public_headers fails on the merge: the exports kept their (void) stubs in include/Api.hpp and the test redeclared them. 75ed618a28 (refactor(libSceLibreSsl3): declare the ASN.1 string exports in the public header) puts the real signatures and their structs in libSceLibreSsl3/include/Api.hpp and drops the test's redeclarations. 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 6e775f452a, head bf3ab34c2f, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Full build and ctest -j16: 2268/2269 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main 74acfad65b (after #10948), head cac850c954, to resolve the conflicts with main on the shared CMakeLists.txt and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. #10948 added a guest_libressl3_asn1 test of its own, so this PR's test is now guest_libressl3_asn1_string, renamed in the commit that adds it. New commit cac850c954 drops LibreSslAsn1String and uses main's Asn1String, which the libSceLibreSsl3 header now includes; the duplicate static_asserts in Asn1.cpp go with it. Full build and ctest -j16: 2431/2432 pass; agc_driver_multisample_retirement fails the same way on that main. check_conventions.py --base upstream/main passes.
  • Rebased on main f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 328cb79364, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep main's names and add this PR's, and the count, 75, matches the stubs in Export.cpp. Full build and ctest -j16: 3157/3157 pass. check_conventions.py --base upstream/main passes.
  • Rebased on main 4939814d79 (after #9535 and #9970), head d774dc3341, to resolve the conflicts on the shared Export.cpp, Api.hpp and debt-file lines; both sides are kept. main says 76 pending exports with 74 stubs left, so the count is set to the 72 stubs left in Export.cpp. Full build and ctest -j16: 3538/3538 pass. check_conventions.py --base upstream/main passes.
  • Merged main b11c7bf84f (after #10557), head b5d72c34ea, to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; both sides are kept, X509_PUBKEY_get0_param stays in the exclusion list, and the count is set to the 71 stubs left in Export.cpp. Full build and ctest -j16: 3883/3883 pass. 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4991243955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10452). Originally posted by [alvaroelpob](https://github.com/alvaroelpob) on 2026-10-24T01:07:33Z. --- ### What Implements `ASN1_STRING_get0_data` and `ASN1_INTEGER_free` in libSceLibreSsl3, which threw and were declared without parameters. The module is LibreSSL 4.0.0 (`OpenSSL_version(0)` and the image string in the [firmware 13.40 measurements in #8981](https://github.com/boykopovar/AnyPS5/discussions/8981#discussioncomment-19111214)). Signatures, the `ASN1_STRING` layout and the results follow that release's [`asn1.h`, `a_string.c`, `a_int.c` and `tasn_fre.c`](https://github.com/libressl/openbsd/tree/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/asn1). `asn1_string_st` is still public there. | Export | Behaviour | |---|---| | `const unsigned char* ASN1_STRING_get0_data(const ASN1_STRING*)` | `data` | | `void ASN1_INTEGER_free(ASN1_INTEGER*)` | nothing for null. Otherwise, as `ASN1_item_free` with `ASN1_INTEGER_it` reaches `ASN1_STRING_free`, it zeroes and frees `data` (`freezero`) unless `ASN1_STRING_FLAG_NDEF` (0x10) is set, then frees the string | The layout is `main`'s 24-byte `Asn1String` (`length`, `type`, `data` at 8, `flags` at 16), which libSceLibreSsl declares and asserts and the libSceLibreSsl3 header includes since #10948. Memory is released through the guest `free`, as the module would through libc. The item free path takes the type from `ASN1_INTEGER_it`, not from the object, so a string of any type is freed the same way. These throw: - a null string in `ASN1_STRING_get0_data`, which LibreSSL dereferences; - a negative `length` with non-null data in `ASN1_INTEGER_free`, which `freezero` would take as a huge `size_t`. No export of this module creates a string yet, so for now only strings built by the caller reach these functions. The debt entry records the source and what is unverified. The pending-export count drops from 84 to 82, and both names join the list of exclusions. ### 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` e2b9700a9. There is one commit per function, and each adds that function with its test block and debt update. Each was built and its `guest_libressl3_asn1` test and `check_conventions.py` run on its own. - New `guest_libressl3_asn1_string` test. `ASN1_STRING_get0_data` returns the stored pointer, including null data and the NDEF flag, and a null string throws. `ASN1_INTEGER_free` is checked on null and on positive, negative, empty and other-typed strings from the guest heap. An NDEF string leaves its data intact, and that data can then be freed by the caller. A negative length with data throws and frees nothing, and the same string is freed once the length is corrected. A negative length with null data frees only the string. On `main` the first call throws. - Full `ctest -j16` at the last commit: 2003/2004 pass. `agc_driver_multisample_retirement` fails the same way on `main` on this machine. - Not tested: Windows, a title. - Rebased on `main` e7e3e9c198, head 75ed618a28. The branch still merged cleanly, but after #10706 `public_headers` fails on the merge: the exports kept their `(void)` stubs in `include/Api.hpp` and the test redeclared them. 75ed618a28 (`refactor(libSceLibreSsl3): declare the ASN.1 string exports in the public header`) puts the real signatures and their structs in `libSceLibreSsl3/include/Api.hpp` and drops the test's redeclarations. 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` 6e775f452a, head bf3ab34c2f, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 84 minus this PR's exports. Full build and `ctest -j16`: 2268/2269 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 74acfad65b (after #10948), head cac850c954, to resolve the conflicts with `main` on the shared `CMakeLists.txt` and debt-file lines; both sides are kept and the count is 83 minus this PR's exports. #10948 added a `guest_libressl3_asn1` test of its own, so this PR's test is now `guest_libressl3_asn1_string`, renamed in the commit that adds it. New commit cac850c954 drops `LibreSslAsn1String` and uses `main`'s `Asn1String`, which the libSceLibreSsl3 header now includes; the duplicate `static_assert`s in `Asn1.cpp` go with it. Full build and `ctest -j16`: 2431/2432 pass; `agc_driver_multisample_retirement` fails the same way on that `main`. `check_conventions.py --base upstream/main` passes. - Rebased on `main` f2d874c1fd (after #10948, #13267, #13831, #13897 and #14171), head 328cb79364, to resolve the conflicts on the pending-export line of the debt file: the count and the exclusion list keep `main`'s names and add this PR's, and the count, 75, matches the stubs in `Export.cpp`. Full build and `ctest -j16`: 3157/3157 pass. `check_conventions.py --base upstream/main` passes. - Rebased on `main` 4939814d79 (after #9535 and #9970), head d774dc3341, to resolve the conflicts on the shared `Export.cpp`, `Api.hpp` and debt-file lines; both sides are kept. `main` says 76 pending exports with 74 stubs left, so the count is set to the 72 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3538/3538 pass. `check_conventions.py --base upstream/main` passes. - Merged `main` b11c7bf84f (after #10557), head b5d72c34ea, to resolve the conflicts on the shared `CMakeLists.txt` and debt-file lines; both sides are kept, `X509_PUBKEY_get0_param` stays in the exclusion list, and the count is set to the 71 stubs left in `Export.cpp`. Full build and `ctest -j16`: 3883/3883 pass. `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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-24 01:07:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-24T01:07:42Z.

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:5636008149 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10452#pullrequestreview-5636008149). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-24T01:07:42Z. **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 01:16:00 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the exact head and its two commits. The claimed LibreSSL 4.0.0 layout is consistent with the cited public header, and returns the data member directly. The path follows the cited item-free/string-free sequence: preserve NDEF data, otherwise zero and free the payload, then free the object through the guest allocator. The 24-byte layout assertions and focused tests cover ordinary, empty, NDEF, other-type, null, and negative-length cases. The PR identifies #9970 as a dependency, which is relevant because both changes touch the LibreSSL3 export/build/debt files. Hosted eligibility, conventions, intake, labels and report checks pass. The author reports 2003/2004 full CTest cases passing with the same multisample failure on base; I did not independently run that suite, and hosted product builds are skipped here. No blocking issue found in this scope.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636069604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10452#pullrequestreview-5636069604). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T01:16:00Z. **Review:** APPROVED --- Reviewed the exact head and its two commits. The claimed LibreSSL 4.0.0 layout is consistent with the cited public header, and returns the data member directly. The path follows the cited item-free/string-free sequence: preserve NDEF data, otherwise zero and free the payload, then free the object through the guest allocator. The 24-byte layout assertions and focused tests cover ordinary, empty, NDEF, other-type, null, and negative-length cases. The PR identifies #9970 as a dependency, which is relevant because both changes touch the LibreSSL3 export/build/debt files. Hosted eligibility, conventions, intake, labels and report checks pass. The author reports 2003/2004 full CTest cases passing with the same multisample failure on base; I did not independently run that suite, and hosted product builds are skipped here. No blocking issue found in this scope.
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!10452
No description provided.