feat(libSceLibreSsl3): implement X509_STORE_CTX_init #19063

Merged
MatteoSid merged 2 commits from upstream-pr/19063 into main 2026-11-13 06:11:03 +00:00
MatteoSid commented 2026-11-12 18:20:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MatteoSid on 2026-11-12T18:20:26Z.


What

Implements X509_STORE_CTX_init (NID PYwVp6yeFp0) in libSceLibreSsl3, following LibreSSL 4.0.0's X509_STORE_CTX_init and the X509_VERIFY_PARAM_new / inherit / lookup it calls. It uses the layouts this module already shares with libSceLibreSsl: the 240-byte context of X509_STORE_CTX_new, the store of X509_STORE_new and its verify parameters.

  • it zeroes the context, sets error to X509_V_ERR_INVALID_CALL (65), and stores the store, leaf and untrusted stack;
  • verify and verify_cb come from the store when set, otherwise from the defaults; get_issuer and check_issued always get the defaults, as in 4.0.0. The other callback slots stay null;
  • it allocates verify parameters (depth -1), inherits them from the store's parameters and then from the built-in default entry (depth 100, X509_V_FLAG_TRUSTED_FIRST). Without a store it sets X509_VP_FLAG_DEFAULT | X509_VP_FLAG_ONCE first. Inheritance handles the DEFAULT, OVERWRITE, RESET_FLAGS, LOCKED and ONCE flags, the check-time rule, and copies of purpose, trust, depth, flags, host flags, host names, e-mail and IP address into new guest-heap allocations;
  • a failed allocation or failed inheritance queues X509 ERR_R_MALLOC_FAILURE and returns 0. The parameters stay attached, as upstream, for X509_STORE_CTX_free to release.

X509_STORE_CTX_free now releases owned parameters (no parent), including the host, peer name, e-mail and IP data. Before, it threw on them, which would have made every initialised context throw on free.

The default verify_cb is LibreSSL's null_callback, which returns ok. internal_verify, X509_STORE_CTX_get1_issuer and check_issued are internal functions that throw through NotImplemented_nid_no_patch when called, the same way libSceLibreSsl's X509_STORE object comparator and file lookup do. Nothing in either module calls them yet, because X509_verify_cert is a stub. Extra data stays libSceLibreSsl's null stack, which the forwarded X509_STORE_CTX_get_ex_data reads. No export can register a context-class constructor: SSL_get_ex_data_X509_STORE_CTX_idx registers none. X509_VERIFY_PARAM_add0_table is not exported, so default is the only parameter table.

Gaps, in a new debt entry: the default callbacks above; inheriting store policies throws (no ASN1_OBJECT deep copy); the 2.5.4 parameter layout keeps a separate identity allocation and has no poisoned flag; errors go to the libSceLibreSsl queue without file or line. The existing X509_STORE_CTX_* entry now describes the new behaviour of free. X509StoreContext.cpp follows x509_vfy.c and x509_vpm.c, so it starts with both notices.

Tested

Linux (Ubuntu 24.04 container, GCC 13.3), configured with -DBUILD_TESTING=ON, Release, on head c03bf828ec based on main 949ac1ffbf. I built every LibreSSL test target and the patched .prx files. ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers' passes all 213 tests.

Windows: JJenkx ran guest_libressl3_x509_store_context on head c03bf828ec merged onto main (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped (comment).

guest_libressl3_x509_store_context now also checks:

  • a store from X509_STORE_new with null leaf and untrusted, on a context filled with 0xA5: every context field, verify_cb returning its ok, X509_STORE_CTX_get_error 65, null X509_STORE_CTX_get_ex_data, parameters distinct from the store's with depth 100, flags 0x8000, no inheritance flags and an empty identity, the store's reference count and parameters unchanged, nothing queued. The context allocates exactly the parameters and their identity, and free releases them along with a host and IP set on them afterwards;
  • a null store with a leaf and an untrusted stack;
  • store verify and verify_cb copied one at a time, and the other store callbacks ignored;
  • inheritance from store parameters with purpose, trust, depth, check time, flags, host flags, a host, an IP and a non-terminated e-mail: everything is copied into new allocations and the store is unchanged. Without USE_CHECK_TIME the default check time wins. LOCKED skips the store, and OVERWRITE copies everything;
  • failures: OVERWRITE without an e-mail, or with an e-mail but no IP; an IP of 3 or 0 bytes; an empty e-mail; an e-mail with a NUL inside its length. Each one returns 0, queues exactly 0x0bfff041, keeps the context fields set, and leaks nothing;
  • a counting allocator fails each of the 7 allocations of an init that copies a host, an e-mail and an IP (2 for the parameters, 2 for the host stack, then the host, e-mail and IP), and the 2 of a store-less init. Each one returns 0 with one malloc-failure error, and free leaves no allocation.

The old free test that set an owned param to a non-parameter marker is removed. That case now reads the parameters.

All 24 mutations make the test fail (run before the last rebase, which changed no file of this PR): no error 65, no zeroing, either store callback ignored, verify_cb returning 1, a reused default, initial depth not -1, the default table skipped, ONCE/LOCKED/OVERWRITE ignored, depth always copied, check time always copied, host flags skipped, hosts shared rather than copied, NUL-in-e-mail or empty e-mail accepted, IP length unchecked, e-mail skipped, no error queued, either failure ignored, owned parameters or their hosts leaked. nm -D on the patched libSceLibreSsl3.prx lists PYwVp6yeFp0. tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch finds no overlap with the open PRs it could compare, including #18946 and #19033. I checked the 15 that conflict with main by hand (#12315, #14212, #14465, #15163, #15737, #16589, #16654, #16689, #16980, #16981, #17528, #17621, #17622, #17626, #18284). None of them changes X509_STORE_CTX_init, X509StoreContext.cpp or the X509_STORE_CTX debt entry. #12315 only has the old stub declaration as context. No title tested.

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:5282867876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19063). Originally posted by [MatteoSid](https://github.com/MatteoSid) on 2026-11-12T18:20:26Z. --- ### What Implements `X509_STORE_CTX_init` (NID `PYwVp6yeFp0`) in libSceLibreSsl3, following LibreSSL 4.0.0's [`X509_STORE_CTX_init`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/x509/x509_vfy.c#L2231-L2306) and the [`X509_VERIFY_PARAM_new` / `inherit` / `lookup`](https://github.com/libressl/openbsd/blob/ce488b78e0bd994780569df718596b9776ff681a/src/lib/libcrypto/x509/x509_vpm.c) it calls. It uses the layouts this module already shares with libSceLibreSsl: the 240-byte context of `X509_STORE_CTX_new`, the store of `X509_STORE_new` and its verify parameters. - it zeroes the context, sets `error` to `X509_V_ERR_INVALID_CALL` (65), and stores the store, leaf and untrusted stack; - `verify` and `verify_cb` come from the store when set, otherwise from the defaults; `get_issuer` and `check_issued` always get the defaults, as in 4.0.0. The other callback slots stay null; - it allocates verify parameters (depth -1), inherits them from the store's parameters and then from the built-in `default` entry (depth 100, `X509_V_FLAG_TRUSTED_FIRST`). Without a store it sets `X509_VP_FLAG_DEFAULT | X509_VP_FLAG_ONCE` first. Inheritance handles the `DEFAULT`, `OVERWRITE`, `RESET_FLAGS`, `LOCKED` and `ONCE` flags, the check-time rule, and copies of purpose, trust, depth, flags, host flags, host names, e-mail and IP address into new guest-heap allocations; - a failed allocation or failed inheritance queues `X509` `ERR_R_MALLOC_FAILURE` and returns 0. The parameters stay attached, as upstream, for `X509_STORE_CTX_free` to release. `X509_STORE_CTX_free` now releases owned parameters (no `parent`), including the host, peer name, e-mail and IP data. Before, it threw on them, which would have made every initialised context throw on free. The default `verify_cb` is LibreSSL's `null_callback`, which returns `ok`. `internal_verify`, `X509_STORE_CTX_get1_issuer` and `check_issued` are internal functions that throw through `NotImplemented_nid_no_patch` when called, the same way libSceLibreSsl's `X509_STORE` object comparator and file lookup do. Nothing in either module calls them yet, because `X509_verify_cert` is a stub. Extra data stays libSceLibreSsl's null stack, which the forwarded `X509_STORE_CTX_get_ex_data` reads. No export can register a context-class constructor: `SSL_get_ex_data_X509_STORE_CTX_idx` registers none. `X509_VERIFY_PARAM_add0_table` is not exported, so `default` is the only parameter table. Gaps, in a new debt entry: the default callbacks above; inheriting store policies throws (no `ASN1_OBJECT` deep copy); the 2.5.4 parameter layout keeps a separate identity allocation and has no `poisoned` flag; errors go to the libSceLibreSsl queue without file or line. The existing `X509_STORE_CTX_*` entry now describes the new behaviour of `free`. `X509StoreContext.cpp` follows `x509_vfy.c` and `x509_vpm.c`, so it starts with both notices. ### Tested Linux (Ubuntu 24.04 container, GCC 13.3), configured with `-DBUILD_TESTING=ON`, Release, on head `c03bf828ec` based on `main` `949ac1ffbf`. I built every LibreSSL test target and the patched `.prx` files. `ctest -R 'libressl|libre_ssl|crypto_memcmp|public_headers'` passes all 213 tests. Windows: JJenkx ran `guest_libressl3_x509_store_context` on head `c03bf828ec` merged onto `main` (Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped ([comment](https://github.com/boykopovar/AnyPS5/pull/19063#issuecomment-6835096628)). `guest_libressl3_x509_store_context` now also checks: - a store from `X509_STORE_new` with null leaf and untrusted, on a context filled with `0xA5`: every context field, `verify_cb` returning its `ok`, `X509_STORE_CTX_get_error` 65, null `X509_STORE_CTX_get_ex_data`, parameters distinct from the store's with depth 100, flags `0x8000`, no inheritance flags and an empty identity, the store's reference count and parameters unchanged, nothing queued. The context allocates exactly the parameters and their identity, and `free` releases them along with a host and IP set on them afterwards; - a null store with a leaf and an untrusted stack; - store `verify` and `verify_cb` copied one at a time, and the other store callbacks ignored; - inheritance from store parameters with purpose, trust, depth, check time, flags, host flags, a host, an IP and a non-terminated e-mail: everything is copied into new allocations and the store is unchanged. Without `USE_CHECK_TIME` the default check time wins. `LOCKED` skips the store, and `OVERWRITE` copies everything; - failures: `OVERWRITE` without an e-mail, or with an e-mail but no IP; an IP of 3 or 0 bytes; an empty e-mail; an e-mail with a NUL inside its length. Each one returns 0, queues exactly `0x0bfff041`, keeps the context fields set, and leaks nothing; - a counting allocator fails each of the 7 allocations of an init that copies a host, an e-mail and an IP (2 for the parameters, 2 for the host stack, then the host, e-mail and IP), and the 2 of a store-less init. Each one returns 0 with one malloc-failure error, and `free` leaves no allocation. The old `free` test that set an owned `param` to a non-parameter marker is removed. That case now reads the parameters. All 24 mutations make the test fail (run before the last rebase, which changed no file of this PR): no error 65, no zeroing, either store callback ignored, `verify_cb` returning 1, a reused default, initial depth not -1, the default table skipped, `ONCE`/`LOCKED`/`OVERWRITE` ignored, depth always copied, check time always copied, host flags skipped, hosts shared rather than copied, NUL-in-e-mail or empty e-mail accepted, IP length unchecked, e-mail skipped, no error queued, either failure ignored, owned parameters or their hosts leaked. `nm -D` on the patched `libSceLibreSsl3.prx` lists `PYwVp6yeFp0`. `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch` finds no overlap with the open PRs it could compare, including #18946 and #19033. I checked the 15 that conflict with `main` by hand (#12315, #14212, #14465, #15163, #15737, #16589, #16654, #16689, #16980, #16981, #17528, #17621, #17622, #17626, #18284). None of them changes `X509_STORE_CTX_init`, `X509StoreContext.cpp` or the `X509_STORE_CTX` debt entry. #12315 only has the old stub declaration as context. No title tested. ### 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
PrivacyOnion commented 2026-11-12 18:31:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T18:31:33Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c03bf828ec:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_x509_store_context_tests built cleanly.
  • CTest (guest_libressl3_x509_store_context):
    1/1 Test #3714: guest_libressl3_x509_store_context ...   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified core/libs/prx/libSceLibreSsl3/Export.cpp and Api.hpp function prototypes for X509_STORE_CTX_init_nid_postfix match PS5 ABI calling conventions and LibreSSL 4.0.0 parameter layouts.
    • Audited core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:X509_STORE_CTX_init_nid_postfix field initializations (error code 65 / X509_V_ERR_INVALID_CALL, callback dispatch indices, and fallback to InternalVerify and NullCallback).
    • Audited X509_STORE_CTX_free_nid_postfix verifying that owned parameters are released only when context->parent is null, and that unhandled policy tree, chain, cleanup, and exData fields throw as documented in docs/dev/debt/libSceLibreSsl3.md.
    • Verified allocation failure paths in NewVerifyParam and X509_STORE_CTX_init_nid_postfix, confirming LibreSslPutError_nid_no_patch queues MallocFailure (0x0bfff041) on out-of-memory.
    • Audited CopyHosts, SetBytes, and SetIp memory management, ensuring strdup and malloc allocations are cleaned up on partial failures without leaking memory.
  • Concerns:
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:268: When inheriting store verify parameters that have InheritOverwrite (X509_VP_FLAG_OVERWRITE, 0x2) set, copy(from->email, to->email) evaluates to true even when from->email is null. This invokes SetBytes(&to->email, &to->emailLength, from->email, from->emailLength, true) with source == nullptr, which returns false at line 210 (if (!source) return false). Consequently, Inherit returns false and X509_STORE_CTX_init_nid_postfix fails, returning 0 and queueing an ERR_R_MALLOC_FAILURE error whenever a store configured with InheritOverwrite does not possess an email address. Upstream LibreSSL 4.0.0 instead clears the destination email to null (identical to the handling of from->hosts at line 265).
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:269: When inheriting store verify parameters with InheritOverwrite (0x2) set and from->email is populated but from->ip is null, copy(from->ip, to->ip) evaluates to true. SetIp is called with ip == nullptr and length == 0, which immediately returns false at line 226 (if (length != 4 && length != 16) return false). This causes Inherit to return false and X509_STORE_CTX_init_nid_postfix to return 0 with an ERR_R_MALLOC_FAILURE error whenever a store with InheritOverwrite lacks an IP address.
    • core/libs/prx/libSceLibreSsl3/tests/X509StoreContext.cpp:426: TestInheritFailures sets source->inheritanceFlags = 0x2 (InheritOverwrite) on a valid store parameter and asserts RequireFailedInit(store, true) both when email/IP are unset and when host/email are set but IP is unset. This test asserts that valid store parameters fail initialization, codifying the null pointer defects in SetBytes and SetIp as expected behavior.
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:245: In Inherit, the lambda copy definition return overwrite || (sourceSet && (toDefault || !destinationSet)); inverts the semantics of InheritDefault (X509_VP_FLAG_DEFAULT, 0x1). Under LibreSSL x509_vpm.c, toDefault signifies that source parameters are default fallbacks and must only be inherited if the destination parameter is not already set (!destinationSet). Conversely, standard inheritance without toDefault allows source parameters to overwrite destination values. Here, when toDefault is true, (toDefault || !destinationSet) evaluates to true, forcing source parameters to overwrite already set destination fields; when toDefault is false, it requires !destinationSet, preventing normal inheritance from overwriting set destination fields.
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:258: In Inherit, destination->flags |= source->flags; unconditionally ORs flags from source into destination->flags. When defaultParam is inherited at line 312, defaultParam.flags (TrustedFirst, 0x8000) is unconditionally merged into destination->flags, even if store->param had already explicitly set verify flags (e.g. 0x4 or 0x6). In LibreSSL 4.0.0, default verify flags are only inherited if the destination flags are completely unset (if (to_default) { if (to->flags == 0) to->flags = from->flags; }). This unconditionally corrupts caller-specified verify flags on initialized contexts.
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:253: In Inherit, if (overwrite || !(destination->flags & UseCheckTime)) checks whether destination lacks UseCheckTime, but fails to check whether source->flags & UseCheckTime is set. When defaultParam is inherited at line 312, defaultParam has checkTime = 0 and lacks UseCheckTime. If a store configured checkTime on its parameters without setting UseCheckTime in flags, !(destination->flags & UseCheckTime) evaluates to true during defaultParam inheritance, causing destination->checkTime to be overwritten with defaultParam.checkTime (0). In LibreSSL 4.0.0, default parameters only inherit check_time if from->flags & X509_V_FLAG_USE_CHECK_TIME is set.
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5879923828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19063#pullrequestreview-5879923828). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T18:31:33Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c03bf828ec`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_x509_store_context_tests` built cleanly. - **CTest** (`guest_libressl3_x509_store_context`): ``` 1/1 Test #3714: guest_libressl3_x509_store_context ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified core/libs/prx/libSceLibreSsl3/Export.cpp and Api.hpp function prototypes for X509_STORE_CTX_init_nid_postfix match PS5 ABI calling conventions and LibreSSL 4.0.0 parameter layouts. - Audited core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:X509_STORE_CTX_init_nid_postfix field initializations (error code 65 / X509_V_ERR_INVALID_CALL, callback dispatch indices, and fallback to InternalVerify and NullCallback). - Audited X509_STORE_CTX_free_nid_postfix verifying that owned parameters are released only when context->parent is null, and that unhandled policy tree, chain, cleanup, and exData fields throw as documented in docs/dev/debt/libSceLibreSsl3.md. - Verified allocation failure paths in NewVerifyParam and X509_STORE_CTX_init_nid_postfix, confirming LibreSslPutError_nid_no_patch queues MallocFailure (0x0bfff041) on out-of-memory. - Audited CopyHosts, SetBytes, and SetIp memory management, ensuring strdup and malloc allocations are cleaned up on partial failures without leaking memory. - **Concerns**: - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:268: When inheriting store verify parameters that have InheritOverwrite (X509_VP_FLAG_OVERWRITE, 0x2) set, copy(from->email, to->email) evaluates to true even when from->email is null. This invokes SetBytes(&to->email, &to->emailLength, from->email, from->emailLength, true) with source == nullptr, which returns false at line 210 (if (!source) return false). Consequently, Inherit returns false and X509_STORE_CTX_init_nid_postfix fails, returning 0 and queueing an ERR_R_MALLOC_FAILURE error whenever a store configured with InheritOverwrite does not possess an email address. Upstream LibreSSL 4.0.0 instead clears the destination email to null (identical to the handling of from->hosts at line 265). - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:269: When inheriting store verify parameters with InheritOverwrite (0x2) set and from->email is populated but from->ip is null, copy(from->ip, to->ip) evaluates to true. SetIp is called with ip == nullptr and length == 0, which immediately returns false at line 226 (if (length != 4 && length != 16) return false). This causes Inherit to return false and X509_STORE_CTX_init_nid_postfix to return 0 with an ERR_R_MALLOC_FAILURE error whenever a store with InheritOverwrite lacks an IP address. - core/libs/prx/libSceLibreSsl3/tests/X509StoreContext.cpp:426: TestInheritFailures sets source->inheritanceFlags = 0x2 (InheritOverwrite) on a valid store parameter and asserts RequireFailedInit(store, true) both when email/IP are unset and when host/email are set but IP is unset. This test asserts that valid store parameters fail initialization, codifying the null pointer defects in SetBytes and SetIp as expected behavior. - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:245: In Inherit, the lambda copy definition return overwrite || (sourceSet && (toDefault || !destinationSet)); inverts the semantics of InheritDefault (X509_VP_FLAG_DEFAULT, 0x1). Under LibreSSL x509_vpm.c, toDefault signifies that source parameters are default fallbacks and must only be inherited if the destination parameter is not already set (!destinationSet). Conversely, standard inheritance without toDefault allows source parameters to overwrite destination values. Here, when toDefault is true, (toDefault || !destinationSet) evaluates to true, forcing source parameters to overwrite already set destination fields; when toDefault is false, it requires !destinationSet, preventing normal inheritance from overwriting set destination fields. - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:258: In Inherit, destination->flags |= source->flags; unconditionally ORs flags from source into destination->flags. When defaultParam is inherited at line 312, defaultParam.flags (TrustedFirst, 0x8000) is unconditionally merged into destination->flags, even if store->param had already explicitly set verify flags (e.g. 0x4 or 0x6). In LibreSSL 4.0.0, default verify flags are only inherited if the destination flags are completely unset (if (to_default) { if (to->flags == 0) to->flags = from->flags; }). This unconditionally corrupts caller-specified verify flags on initialized contexts. - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:253: In Inherit, if (overwrite || !(destination->flags & UseCheckTime)) checks whether destination lacks UseCheckTime, but fails to check whether source->flags & UseCheckTime is set. When defaultParam is inherited at line 312, defaultParam has checkTime = 0 and lacks UseCheckTime. If a store configured checkTime on its parameters without setting UseCheckTime in flags, !(destination->flags & UseCheckTime) evaluates to true during defaultParam inheritance, causing destination->checkTime to be overwritten with defaultParam.checkTime (0). In LibreSSL 4.0.0, default parameters only inherit check_time if from->flags & X509_V_FLAG_USE_CHECK_TIME is set. - Note: the AI-assisted checkbox can stay. Requesting changes for the points above.
MarcZX10 commented 2026-11-12 19:16:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T19:16:10Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

  • Head c03bf828ecb774e0f62443066bd6eda4561d316e, base main. No merged-preview check was run.
  • Read the description, the commit list, the manifest and the diff hunks of the five files in the reviewed list. I did not read the full text of those files.
  • Repository reads at the head with the reader:
python3 repo_read.py search X509_STORE_CTX_init
python3 repo_read.py search LibreSslX509VerifyParam
python3 repo_read.py search LibreSslPutError_nid_no_patch
python3 repo_read.py search strdup_nid_postfix
python3 repo_read.py search "OpenSSL Project"
python3 repo_read.py cat core/libs/prx/libSceLibreSsl/include/Api.hpp 20 50
  • No build, no test run, no change to the repository.

Results

Check Result Note
Changed hunks, five files passed no defect found in the hunks
Verify parameter layout vs defaultParam passed field order matches the struct
ctest on 213 tests not run author-reported
24 mutation runs not run author-reported
check_conventions.py not run author-reported

Findings

Blocking

None.

Non-blocking

  1. core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:170: NewVerifyParam (line 188 for FreeVerifyParam, line 240 for Inherit) repeats helpers that core/libs/prx/libSceLibreSsl/src/X509Store.cpp:137 already has for the same struct. I did not check whether the two modules can share them.
  2. core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:288: the memset in X509_STORE_CTX_init drops any param already attached to the context, so a second init on the same context leaks the first parameter set and its identity. Smallest fix: release an attached param before the memset, or state in the debt entry that init must only run on a fresh context. I did not check upstream for this.

Not verified

  • Full text of the five changed files. The review covers their diff hunks only.
  • The build, the ctest run, the 24 mutation runs and check_conventions.py. These come from the description and were not reproduced.
  • Whether LibreSSL 4.0.0 int_x509_param_set1 fails on a null e-mail or IP under OVERWRITE, as the failure tests assume. Not checked against upstream.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5880581355 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19063#pullrequestreview-5880581355). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T19:16:10Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran - Head `c03bf828ecb774e0f62443066bd6eda4561d316e`, base `main`. No merged-preview check was run. - Read the description, the commit list, the manifest and the diff hunks of the five files in the reviewed list. I did not read the full text of those files. - Repository reads at the head with the reader: ``` python3 repo_read.py search X509_STORE_CTX_init python3 repo_read.py search LibreSslX509VerifyParam python3 repo_read.py search LibreSslPutError_nid_no_patch python3 repo_read.py search strdup_nid_postfix python3 repo_read.py search "OpenSSL Project" python3 repo_read.py cat core/libs/prx/libSceLibreSsl/include/Api.hpp 20 50 ``` - No build, no test run, no change to the repository. ## Results | Check | Result | Note | |---|---|---| | Changed hunks, five files | passed | no defect found in the hunks | | Verify parameter layout vs `defaultParam` | passed | field order matches the struct | | `ctest` on 213 tests | not run | author-reported | | 24 mutation runs | not run | author-reported | | `check_conventions.py` | not run | author-reported | ## Findings ### Blocking None. ### Non-blocking 1. `core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:170`: `NewVerifyParam` (line 188 for `FreeVerifyParam`, line 240 for `Inherit`) repeats helpers that `core/libs/prx/libSceLibreSsl/src/X509Store.cpp:137` already has for the same struct. I did not check whether the two modules can share them. 2. `core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp:288`: the `memset` in `X509_STORE_CTX_init` drops any `param` already attached to the context, so a second init on the same context leaks the first parameter set and its identity. Smallest fix: release an attached `param` before the `memset`, or state in the debt entry that init must only run on a fresh context. I did not check upstream for this. ## Not verified - Full text of the five changed files. The review covers their diff hunks only. - The build, the `ctest` run, the 24 mutation runs and `check_conventions.py`. These come from the description and were not reproduced. - Whether LibreSSL 4.0.0 `int_x509_param_set1` fails on a null e-mail or IP under `OVERWRITE`, as the failure tests assume. Not checked against upstream. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-13 03:12:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T03:12:31Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 2010cd66e5:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_libressl3_x509_store_context_tests built cleanly.
  • CTest (guest_libressl3_x509_store_context):
    1/1 Test #3714: guest_libressl3_x509_store_context ...   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/Export.cpp, core/libs/prx/libSceLibreSsl3/include/Api.hpp, core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified X509_STORE_CTX_init_nid_postfix parameter validation, context zeroing, error code initialization to InvalidCall (65), and callback fallback resolution against LibreSSL 4.0.0 defaults (InternalVerify, NullCallback, GetIssuer, CheckIssued).
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified Inherit handling of inheritance flags (InheritDefault, InheritOverwrite, InheritResetFlags, InheritLocked, InheritOnce), UseCheckTime preservation, and deep copies of host stack, email, and IP buffers matching upstream x509_vpm.c.
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified memory safety and absence of leaks in NewVerifyParam, CopyHosts, SetBytes, SetIp, and FreeVerifyParam across partial and failed allocation paths.
    • core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified X509_STORE_CTX_free_nid_postfix correctly releases owned verify parameters while preserving parent-owned parameters and enforcing CheckReleasable constraints.
    • core/libs/prx/libSceLibreSsl3/tests/X509StoreContext.cpp: verified unit test coverage across default parameters, custom store callbacks, parameter inheritance, negative validation edge cases, and systematic allocation fault injection.
    • docs/dev/debt/libSceLibreSsl3.md: verified technical debt documentation accurately describes the stubbed internal callbacks, verify policy handling, and error queue integration.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5885459522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19063#pullrequestreview-5885459522). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T03:12:31Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `2010cd66e5`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_libressl3_x509_store_context_tests` built cleanly. - **CTest** (`guest_libressl3_x509_store_context`): ``` 1/1 Test #3714: guest_libressl3_x509_store_context ... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/Export.cpp`, `core/libs/prx/libSceLibreSsl3/include/Api.hpp`, `core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified X509_STORE_CTX_init_nid_postfix parameter validation, context zeroing, error code initialization to InvalidCall (65), and callback fallback resolution against LibreSSL 4.0.0 defaults (InternalVerify, NullCallback, GetIssuer, CheckIssued). - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified Inherit handling of inheritance flags (InheritDefault, InheritOverwrite, InheritResetFlags, InheritLocked, InheritOnce), UseCheckTime preservation, and deep copies of host stack, email, and IP buffers matching upstream x509_vpm.c. - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified memory safety and absence of leaks in NewVerifyParam, CopyHosts, SetBytes, SetIp, and FreeVerifyParam across partial and failed allocation paths. - core/libs/prx/libSceLibreSsl3/src/X509StoreContext.cpp: verified X509_STORE_CTX_free_nid_postfix correctly releases owned verify parameters while preserving parent-owned parameters and enforcing CheckReleasable constraints. - core/libs/prx/libSceLibreSsl3/tests/X509StoreContext.cpp: verified unit test coverage across default parameters, custom store callbacks, parameter inheritance, negative validation edge cases, and systematic allocation fault injection. - docs/dev/debt/libSceLibreSsl3.md: verified technical debt documentation accurately describes the stubbed internal callbacks, verify policy handling, and error queue integration. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!19063
No description provided.