feat(libSceLibreSsl): release OCSP response ownership #12850

Closed
PrivacyOnion wants to merge 1 commit from upstream-pr/12850 into main
PrivacyOnion commented 2026-10-29 12:37:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-10-29T12:37:06Z.


What

Implement OCSP_RESPONSE_free, including optional response bytes, nested ASN.1 strings, dynamic OID names/data/containers, static OIDs and NDEF borrowed data. Owned string/OID bytes are cleared before release. Members are released in reverse ASN.1 sequence order through the application allocator.

The layouts and ownership rules follow LibreSSL 2.5.4, specifically ocsp/ocsp.h, ocsp/ocsp_asn.c, asn1/tasn_fre.c, asn1/asn1_lib.c and asn1/a_object.c. Negative lengths for owned non-null data throw before any member is freed. Console/allocator interoperability remains unverified and is recorded in debt.

The overlap checker reports shared library header/CMake/debt contexts. No inspected open PR implements this export; this change does not depend on the pending OCSP accessor work.

Tested

Windows 11, MinGW-w64 GCC 16.1, Release full-runtime CMake configuration. Built guest_libressl_ocsp_response_ownership_tests. CTest passed guest_libressl_ocsp_response_ownership, guest_libressl_x509_errors, guest_libressl_asn1 and guest_libressl3_key_reference.

The new recording-allocator test checks full nested release order, clearing before release, null members, static/dynamic OID flags, NDEF borrowed data and rejection of a negative owned length without partial destruction. Public-header audit passed: 373 libraries / 13,938 exports. Conventions checked against origin/main and upstream/main.

A separate locally built LibreSSL 2.5.4 native probe confirmed the 16-byte OCSP response layout and preservation of static OID / NDEF borrowed data, including a negative borrowed length. No title or console execution was performed.

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:5068119768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12850). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-10-29T12:37:06Z. --- ### What Implement `OCSP_RESPONSE_free`, including optional response bytes, nested ASN.1 strings, dynamic OID names/data/containers, static OIDs and NDEF borrowed data. Owned string/OID bytes are cleared before release. Members are released in reverse ASN.1 sequence order through the application allocator. The layouts and ownership rules follow [LibreSSL 2.5.4](https://github.com/libressl/openbsd/tree/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto), specifically `ocsp/ocsp.h`, `ocsp/ocsp_asn.c`, `asn1/tasn_fre.c`, `asn1/asn1_lib.c` and `asn1/a_object.c`. Negative lengths for owned non-null data throw before any member is freed. Console/allocator interoperability remains unverified and is recorded in debt. The overlap checker reports shared library header/CMake/debt contexts. No inspected open PR implements this export; this change does not depend on the pending OCSP accessor work. ### Tested Windows 11, MinGW-w64 GCC 16.1, Release full-runtime CMake configuration. Built `guest_libressl_ocsp_response_ownership_tests`. CTest passed `guest_libressl_ocsp_response_ownership`, `guest_libressl_x509_errors`, `guest_libressl_asn1` and `guest_libressl3_key_reference`. The new recording-allocator test checks full nested release order, clearing before release, null members, static/dynamic OID flags, NDEF borrowed data and rejection of a negative owned length without partial destruction. Public-header audit passed: 373 libraries / 13,938 exports. Conventions checked against origin/main and upstream/main. A separate locally built LibreSSL 2.5.4 native probe confirmed the 16-byte OCSP response layout and preservation of static OID / NDEF borrowed data, including a negative borrowed length. No title or console execution was performed. <!-- 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. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
XairRrR commented 2026-10-29 12:41:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T12:41:30Z.

Review: APPROVED


Reviewed — approved

OCSP_RESPONSE_free frees the same members, in the same order, as LibreSSL 2.5.4's ASN1_item_free / ASN1_STRING_free / ASN1_OBJECT_free. The new test passes and fails under every mutation I tried.

What I ran

  • PR head: 59912e5595f9700cd005e612e4deaaded7f869dc
  • main: 5454cd2e455994d992aca39335ce60507eeda1eb
  • Host: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF. Release build with Ninja and BUILD_TESTING=ON, in a clean worktree with the PR merged into main (--no-ff, no conflicts).
git diff --check origin/main...refs/review/12850
python3 tools/check_conventions.py --base origin/main
cmake --build build -j10 --target libs guest_libressl_ocsp_response_ownership_tests <all other guest_libressl*_tests targets>
ctest --test-dir build -R guest_libressl -j4 --output-on-failure
ctest --test-dir build -R guest_libressl_ocsp_response_ownership -V
nm -D build/core/libs/libs/unpatched/libSceLibreSsl.prx | grep OCSP_RESPONSE_free
# negative control: see below

Results

Check Result
Merge into main Clean
git diff --check Clean
check_conventions.py --base origin/main All conventions checks passed.
Build libs + all 27 libressl test targets OK, NID patching OK
ctest -R guest_libressl (33 tests) 33/33 passed
guest_libressl_ocsp_response_ownership Passed, 0.00 s (timeout 20 s)
Export present in the module T OCSP_RESPONSE_free_nid_postfix
Pending-export count in debt (299 → 298) Matches: NotImplemented_nid_no_patch(__func__) count in Export.cpp goes from 299 on main to 298
ctest excerpt
2094: OCSP response ownership checks passed
1/1 Test #2094: guest_libressl_ocsp_response_ownership ...   Passed    0.00 sec
...
100% tests passed out of 33

I compared the implementation with the LibreSSL 2.5.4 sources at the commit the PR cites:

  • ocsp_asn.c L428-L452: OCSP_RESPONSE is {ENUMERATED responseStatus, [0] EXPLICIT OPTIONAL OCSP_RESPBYTES responseBytes}, and OCSP_RESPBYTES is {OBJECT responseType, OCTET STRING response}.
  • tasn_fre.c L137-L166: a SEQUENCE frees its fields in reverse template order, then frees itself. That gives response → responseType → bytes → responseStatus → response, which is the order in src/OcspResponseOwnership.cpp:65-71.
  • asn1_lib.c L434-L444 (ASN1_STRING_FLAG_NDEF = 0x10) and a_object.c L372-L391 (flags 0x1/0x4/0x8): FreeString and FreeObject match these, including clearing the bytes before freeing and resetting sn/ln/data/length on static objects.

Throwing on a negative owned length, where upstream would pass a huge size_t to explicit_bzero, follows the "throw where LibreSSL faults" pattern already used in this library. The debt entry records it.

Negative control

Restoring only the production files from main (Export.cpp, include/Api.hpp, and removing src/OcspResponseOwnership.cpp) stops the build, because the CMake block in the same file names the source. That shows nothing about the test, so I mutated src/OcspResponseOwnership.cpp instead and rebuilt the test for each mutation:

Mutation Test result
Function throws (stub) Fails (what(): stub)
responseType freed before response Fails (check failed at line 111)
String bytes not cleared before release Fails (line 60)
Validate removed Fails (line 60)
NDEF flag ignored Fails (line 57)
Object without ASN1_OBJECT_FLAG_DYNAMIC freed Fails (line 57)

After restoring the PR file, the test passes again.

Findings

Blocking

None.

Non-blocking

  1. Duplicate response layout with an open PR. #10448 adds struct LibreSslOcspResponse { Asn1String* responseStatus; void* responseBytes; } to include/Api.hpp for the same 16-byte object. This PR adds OcspResponse / OcspResponseBytes in a new header (include/OcspResponseOwnership.hpp L9-L17). The two do not conflict textually, but whichever PR lands second leaves two structs for one guest object. Suggestion: reuse one definition once the other PR merges. The LibreSsl prefix also matches neighbouring layouts such as LibreSslAsn1Object.
  2. Stray blank lines. Removing the stub leaves two consecutive blank lines in Export.cpp (L796-L797). The new CMake block also starts after two blank lines (CMakeLists.txt L283-L284). This is cosmetic.

Not verified

  • PS5 console behaviour and whether guest-allocated OCSP objects share this allocator. The PR records this as debt, and no export in this module builds an OCSP_RESPONSE yet.
  • The Windows/MinGW build and test run described in the PR. I tested only on Linux/GCC.
  • The PR's separate native LibreSSL 2.5.4 probe. I compared against the sources only.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5697836887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12850#pullrequestreview-5697836887). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T12:41:30Z. **Review:** APPROVED --- # Reviewed — approved `OCSP_RESPONSE_free` frees the same members, in the same order, as LibreSSL 2.5.4's `ASN1_item_free` / `ASN1_STRING_free` / `ASN1_OBJECT_free`. The new test passes and fails under every mutation I tried. ## What I ran - PR head: `59912e5595f9700cd005e612e4deaaded7f869dc` - `main`: `5454cd2e455994d992aca39335ce60507eeda1eb` - Host: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF. Release build with Ninja and `BUILD_TESTING=ON`, in a clean worktree with the PR merged into `main` (`--no-ff`, no conflicts). ```sh git diff --check origin/main...refs/review/12850 python3 tools/check_conventions.py --base origin/main cmake --build build -j10 --target libs guest_libressl_ocsp_response_ownership_tests <all other guest_libressl*_tests targets> ctest --test-dir build -R guest_libressl -j4 --output-on-failure ctest --test-dir build -R guest_libressl_ocsp_response_ownership -V nm -D build/core/libs/libs/unpatched/libSceLibreSsl.prx | grep OCSP_RESPONSE_free # negative control: see below ``` ## Results | Check | Result | |---|---| | Merge into `main` | Clean | | `git diff --check` | Clean | | `check_conventions.py --base origin/main` | `All conventions checks passed.` | | Build `libs` + all 27 libressl test targets | OK, NID patching OK | | `ctest -R guest_libressl` (33 tests) | 33/33 passed | | `guest_libressl_ocsp_response_ownership` | Passed, 0.00 s (timeout 20 s) | | Export present in the module | `T OCSP_RESPONSE_free_nid_postfix` | | Pending-export count in debt (299 → 298) | Matches: `NotImplemented_nid_no_patch(__func__)` count in `Export.cpp` goes from 299 on `main` to 298 | <details><summary>ctest excerpt</summary> ``` 2094: OCSP response ownership checks passed 1/1 Test #2094: guest_libressl_ocsp_response_ownership ... Passed 0.00 sec ... 100% tests passed out of 33 ``` </details> I compared the implementation with the LibreSSL 2.5.4 sources at the commit the PR cites: - [`ocsp_asn.c` L428-L452](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/ocsp/ocsp_asn.c#L428-L452): `OCSP_RESPONSE` is `{ENUMERATED responseStatus, [0] EXPLICIT OPTIONAL OCSP_RESPBYTES responseBytes}`, and `OCSP_RESPBYTES` is `{OBJECT responseType, OCTET STRING response}`. - [`tasn_fre.c` L137-L166](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/asn1/tasn_fre.c#L137-L166): a SEQUENCE frees its fields in reverse template order, then frees itself. That gives response → responseType → bytes → responseStatus → response, which is the order in `src/OcspResponseOwnership.cpp:65-71`. - [`asn1_lib.c` L434-L444](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/asn1/asn1_lib.c#L434-L444) (`ASN1_STRING_FLAG_NDEF` = 0x10) and [`a_object.c` L372-L391](https://github.com/libressl/openbsd/blob/2e2c612066aa993717528a0249c15c51128d61cb/src/lib/libcrypto/asn1/a_object.c#L372-L391) (flags 0x1/0x4/0x8): `FreeString` and `FreeObject` match these, including clearing the bytes before freeing and resetting `sn`/`ln`/`data`/`length` on static objects. Throwing on a negative owned length, where upstream would pass a huge `size_t` to `explicit_bzero`, follows the "throw where LibreSSL faults" pattern already used in this library. The debt entry records it. ## Negative control Restoring only the production files from `main` (`Export.cpp`, `include/Api.hpp`, and removing `src/OcspResponseOwnership.cpp`) stops the build, because the CMake block in the same file names the source. That shows nothing about the test, so I mutated `src/OcspResponseOwnership.cpp` instead and rebuilt the test for each mutation: | Mutation | Test result | |---|---| | Function throws (stub) | Fails (`what(): stub`) | | `responseType` freed before `response` | Fails (`check failed at line 111`) | | String bytes not cleared before release | Fails (line 60) | | `Validate` removed | Fails (line 60) | | NDEF flag ignored | Fails (line 57) | | Object without `ASN1_OBJECT_FLAG_DYNAMIC` freed | Fails (line 57) | After restoring the PR file, the test passes again. ## Findings ### Blocking None. ### Non-blocking 1. **Duplicate response layout with an open PR.** #10448 adds `struct LibreSslOcspResponse { Asn1String* responseStatus; void* responseBytes; }` to `include/Api.hpp` for the same 16-byte object. This PR adds `OcspResponse` / `OcspResponseBytes` in a new header ([`include/OcspResponseOwnership.hpp` L9-L17](https://github.com/boykopovar/AnyPS5/blob/59912e5595f9700cd005e612e4deaaded7f869dc/core/libs/prx/libSceLibreSsl/include/OcspResponseOwnership.hpp#L9-L17)). The two do not conflict textually, but whichever PR lands second leaves two structs for one guest object. Suggestion: reuse one definition once the other PR merges. The `LibreSsl` prefix also matches neighbouring layouts such as `LibreSslAsn1Object`. 2. **Stray blank lines.** Removing the stub leaves two consecutive blank lines in `Export.cpp` ([L796-L797](https://github.com/boykopovar/AnyPS5/blob/59912e5595f9700cd005e612e4deaaded7f869dc/core/libs/prx/libSceLibreSsl/Export.cpp#L796-L797)). The new CMake block also starts after two blank lines ([`CMakeLists.txt` L283-L284](https://github.com/boykopovar/AnyPS5/blob/59912e5595f9700cd005e612e4deaaded7f869dc/core/libs/prx/libSceLibreSsl/CMakeLists.txt#L283-L284)). This is cosmetic. ## Not verified - PS5 console behaviour and whether guest-allocated OCSP objects share this allocator. The PR records this as debt, and no export in this module builds an `OCSP_RESPONSE` yet. - The Windows/MinGW build and test run described in the PR. I tested only on Linux/GCC. - The PR's separate native LibreSSL 2.5.4 probe. I compared against the sources only.

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!12850
No description provided.