Skip to content

feat(libSceLibreSsl3): implement ASN1_STRING_get0_data and ASN1_INTEGER_free - #10452

Open
alvaroelpob wants to merge 4 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl3-asn1-integer-free
Open

alvaroelpob wants to merge 4 commits into
boykopovar:mainfrom
alvaroelpob:feat/libscelibressl3-asn1-integer-free

Conversation

@alvaroelpob

@alvaroelpob alvaroelpob commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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 e2b9700. 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 e7e3e9c, head 75ed618. The branch still merged cleanly, but after refactor(libs): add full export headers for libs #10706 public_headers fails on the merge: the exports kept their (void) stubs in include/Api.hpp and the test redeclared them. 75ed618 (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 6e775f4, head bf3ab34, 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 74acfad (after feat(libSceLibreSsl3): implement ASN.1 integer decoding #10948), head cac850c, 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. feat(libSceLibreSsl3): implement ASN.1 integer decoding #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 cac850c 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.

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: feat(libressl3): report OpenSSL version strings #9970
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Copilot AI balanced review requested due to automatic review settings October 24, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Progress report (b1b5353 → 74d4470)

📈 System libraries: 27.24% (+0.0078%, +2 implemented functions)

✅ 2 implemented
Library Name
libSceLibreSsl3 ASN1_INTEGER_free_nid_postfix
libSceLibreSsl3 ASN1_STRING_get0_data_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibreSsl3 8/270 (2.96%) 10/270 (3.70%) +0.74%

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MarcZX10

Copy link
Copy Markdown
Contributor

I opened #10461 for the separate ASN1_OBJECT_free export. The overlap scan found shared CMake and debt-file edits with #9970 and this PR, but no duplicate export. I declared both as dependencies so this follow-up lands after the LibreSSL 3 version and ASN.1 work. Please let me know if you prefer a different order.

@alvaroelpob

Copy link
Copy Markdown
Contributor Author

That order works. A local tools/pr_overlap.py run confirms that #10461 shares CMakeLists.txt, Export.cpp and debt-file lines with this PR. It isn't a duplicate export. This PR keeps Depends on: #9970, and #10461 rebases after it.

@github-actions

github-actions Bot commented Oct 24, 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 10960 core/libs/prx/libSceLibreSsl3/CMakeLists.txt L1, L49-50
docs/dev/debt/libSceLibreSsl3.md L5
PR 12578 docs/dev/debt/libSceLibreSsl3.md L5
PR 12580 docs/dev/debt/libSceLibreSsl3.md L5
PR 12582 docs/dev/debt/libSceLibreSsl3.md L5
PR 12754 docs/dev/debt/libSceLibreSsl3.md L5
PR 13267 docs/dev/debt/libSceLibreSsl3.md L5

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 9571 core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md
PR 12945 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
core/libs/prx/libSceLibreSsl3/Export.cpp
core/libs/prx/libSceLibreSsl3/include/Api.hpp
docs/dev/debt/libSceLibreSsl3.md

@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main e7e3e9c, head 75ed618. 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. 75ed618 puts the real signatures and their structs in include/Api.hpp and drops the redeclarations. Full suite 2202/2203, with the same failure on main.

@ycbuzi

ycbuzi commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Windows run of 75ed618a28 merged onto main 49d9c1c751 (f09bac39f7, clean). Windows 11 Home 10.0.26200, WinLibs MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

  • Built guest_libressl3_asn1_tests with no errors or warnings.
  • ctest --repeat until-fail:2: guest_libressl3_asn1 passes both runs.
  • No negative control: the implementation is a new source file, so main's tree can't build this test without it.

Not run: a title. AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl3-asn1-integer-free branch from 75ed618 to bf3ab34 Compare October 25, 2026 18:51
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 25, 2026
@alvaroelpob

alvaroelpob commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on main 6e775f4 (head bf3ab34) to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; no change to this PR's functions. Full ctest -j16 2268/2269, agc_driver_multisample_retirement fails the same way on main. Depends on is unchanged (#9970).

@BunnyFl

BunnyFl commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

The layout matches firmware 13.42's libSceLibreSsl3.sprx for ASN1_STRING_get0_data. I ran the 13.42 versions in an emulator on structures filled with offset markers (every 4-byte word holds its own offset), so a getter's result names the field it read. Two runs gave identical results.

It reads +0x8 of the ASN1_STRING, the data offset in your static_asserts. type (4), flags (16) and the size aren't touched by this call, so I can't confirm those.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl3-asn1-integer-free branch from bf3ab34 to cac850c Compare October 26, 2026 22:37
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 74acfad (after #10948; head cac850c) to resolve the conflicts on the shared CMakeLists.txt and debt-file lines; no change to this PR's functions. #10948 added its own guest_libressl3_asn1 test, so this PR's test is renamed guest_libressl3_asn1_string in the commit that adds it. New commit cac850c uses main's Asn1String, which the libSceLibreSsl3 header now includes, instead of LibreSslAsn1String, and drops the duplicate static_asserts. Full ctest -j16 2431/2432, agc_driver_multisample_retirement fails the same way on main.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 26, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl3-asn1-integer-free branch from cac850c to 931f69d Compare October 27, 2026 12:02
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main 8ff4baf (head 931f69d) to resolve the conflict from #11165 on the shared CMakeLists.txt and debt-file lines; the pending count and its exclusion list keep both sides. Full suite 2543/2544, with agc_driver_multisample_retirement failing on main too; conventions pass.

@alvaroelpob
alvaroelpob force-pushed the feat/libscelibressl3-asn1-integer-free branch from 931f69d to 74d4470 Compare October 30, 2026 14:00
@alvaroelpob

Copy link
Copy Markdown
Contributor Author

Rebased on main da026c7 (head 74d4470) to resolve the conflicts on the shared debt-file lines; no change to this PR's functions. The pending count (79) matches the stubs left in Export.cpp and the exclusion list keeps both sides. Full ctest -j16 3007/3007 (main 3006/3006), conventions pass. Depends on is unchanged.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants