Skip to content

fix(libSceLibreSsl3): report mismatched key types through the error queue - #16655

Merged
adriadam10 merged 5 commits into
boykopovar:mainfrom
MarrasFederico:fix/libressl3-key-getter-type-errors
Nov 11, 2026
Merged

adriadam10 merged 5 commits into
boykopovar:mainfrom
MarrasFederico:fix/libressl3-key-getter-type-errors

Conversation

@MarrasFederico

@MarrasFederico MarrasFederico commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #15601, which GitHub closed when the head fork was deleted. The commits are unchanged; earlier review comments and Windows checks are on #15601.

What

A mismatched key type previously threw std::runtime_error. LibreSSL 4.0.0 instead returns null and queues an EVP error: RSA, DSA, and DH. The adapted accessor implementation now appends that error to the calling thread's existing parent-library queue.

RSA accepts types 6 and 912, DSA accepts 116, and DH accepts 28. Other types return null and queue library 6, function 0xfff, and reasons 127, 129, or 128 respectively. Matching keys return their borrowed inner pointer, including null, without changing references or clearing existing errors. The source file retains the original notices and pinned provenance.

  • The existing 32-byte key layout and use of the parent error queue remain unmeasured on PS5.
  • A null outer key retains the existing invalid_argument exception; upstream dereferences it.
  • The library debt entry records these limits. No constructor, destructor, or ownership behavior is added.

The second commit applies the same treatment to the two neighbouring p_lib.c paths that dropped their error. Both now queue through the same parent-library queue:

Neither path was measured on a console.

Tested

Ubuntu 26.04.1, kernel 7.0.0-42-generic, GCC 15, Release, BUILD_TESTING=ON, on main 04a9eb4fa2, then again after merging main 4741457fed. Windows and macOS were not compiled here. No title was run.

  • Rebuilt guest_libressl3_pkey_getters_tests separately for every control. The test covers recognized and unknown key types, the mismatch cross-product, empty matching keys, borrowed pointers, reference and field preservation, errno, and thread isolation. Ordered queue draining checks that older errors survive subsequent mismatches and successful calls.
  • Main implementation with the extended test: CTest exit 8, reporting the existing mismatched-type exception. Fixed implementation: exit 0. Removing error publication: exit 8 (assertion abort). Clearing the queue before publication: exit 8 (FIFO assertion abort). Restoring the fix: exit 0.
  • Rebuilt the relevant library targets and ran ctest --test-dir build -R 'libressl3|crypto_memcmp|libressl_errors|public_headers' -j6 --output-on-failure: 77/77 passed, including all 65 public-header tests.
  • After merging main 4741457fed: all 13 LibreSSL3 tests pass, including guest_libressl3_pkey_getters. The only conflict was in the debt file: main's newer entries are kept, and this PR's getter entry replaces the old one.
  • python3 tools/check_conventions.py --base origin/main and git diff --check origin/main passed after rebase. Repeated open/closed PR searches for all three symbols and PkeyGetters.cpp; the closed accessor implementations are already represented in main, and the open component accessors do not implement this mismatch fix.
  • pr_overlap.py examined 1775 open PRs and exited 2. It reported debt-line overlaps with feat(libSceLibreSsl): implement EC groups and keys for named curves #10395 (EC keys), feat(libSceLibreSsl3): implement EVP digest contexts and SHA methods #10960 (digest operations), feat(libSceLibreSsl3): implement BIO_up_ref #12945 (BIO/SSL retains), and feat(libSceLibreSsl3): implement RSA_get0_factors and RSA_get0_crt_params #14366 (RSA component getters). I compared their diffs: their debt edits require reconciliation, but none changes these three mismatch paths.

Each comparison the tool could not complete was inspected manually:

These are shared-file conflicts, not dependencies on unmerged implementations.

Second commit (get0_EC_KEY and EVP_PKEY_new), tested on Ubuntu 26.04.1 with GCC 15.2.0, Release, on head fdc5484054 merged with main b53b6c9f7d:

  • ctest -R libressl3: 43/43 passed.
  • guest_libressl3_pkey_getters adds the EC cross-product with the same checks as the other getters (errno, references, fields, queue order).
  • guest_libressl3_pkey_lifecycle checks that a failed EVP_PKEY_new queues 0x06fff041, read back through the module's forwarded ERR_get_error.
  • Negative control: with the EC queueing removed, the getters test aborts at line 193; with it restored, it passes.
  • I searched all 1954 open PRs for these files. Only fix(libSceLibreSsl3): count BIO_up_ref at the forwarded BIO's offset #16926 (BIO_up_ref) touches Key.cpp, and it merges cleanly with this branch. Its only conflict is with main itself, in Api.hpp.

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

…ueue

Publish an EVP library error code with function 0xfff and reasons
EVP_R_EXPECTING_AN_RSA_KEY (127), EVP_R_EXPECTING_A_DSA_KEY (129)
or EVP_R_EXPECTING_A_DH_KEY (128) through the shared parent error queue
when EVP_PKEY_get0_RSA, EVP_PKEY_get0_DSA or EVP_PKEY_get0_DH receives
a mismatched key type, returning null as in LibreSSL 4.0.0's p_lib.c.
Preserve existing null-key handling and leave matching keys and references
unaltered.
# Conflicts:
#	docs/dev/debt/libSceLibreSsl3.md
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

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 12315 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 14212 docs/dev/debt/libSceLibreSsl3.md
PR 14465 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 15163 docs/dev/debt/libSceLibreSsl3.md
PR 15618 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 15737 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 16589 docs/dev/debt/libSceLibreSsl3.md
PR 16819 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 16848 docs/dev/debt/libSceLibreSsl3.md
PR 16918 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 16977 docs/dev/debt/libSceLibreSsl3.md
PR 16979 docs/dev/debt/libSceLibreSsl3.md
PR 16980 docs/dev/debt/libSceLibreSsl3.md
PR 16981 docs/dev/debt/libSceLibreSsl3.md
PR 16996 docs/dev/debt/libSceLibreSsl3.md
PR 17544 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 17621 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 17622 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md
PR 17626 core/libs/prx/libSceLibreSsl3/CMakeLists.txt
docs/dev/debt/libSceLibreSsl3.md

@JJenkx

JJenkx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 7587e4cac3, merged onto main c32f751139 (04c9280b40, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_libressl3_pkey_getters passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions github-actions Bot added build docs prx needs rebase Conflicts with main, rebase needed labels Nov 7, 2026
# Conflicts:
#	core/libs/prx/libSceLibreSsl3/tests/PkeyGetters.cpp
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 8, 2026
…d EVP_PKEY_new

EVP_PKEY_get0_EC_KEY returned NULL for a key of another type without
queueing EVP_R_EXPECTING_A_EC_KEY, and EVP_PKEY_new returned NULL on
allocation failure without queueing ERR_R_MALLOC_FAILURE, both of which
LibreSSL's p_lib.c queue. They now report through the libSceLibreSsl
queue like the RSA, DSA and DH getters.
@adriadam10 adriadam10 self-assigned this Nov 11, 2026
@adriadam10
adriadam10 merged commit f2efd2d into boykopovar:main Nov 11, 2026
15 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the mismatch paths against LibreSSL 4.0.0 p_lib.c (error library 6, function 0xfff, reasons 127/129/128/142, malloc failure 65), the tests (queue order, errno, references, thread isolation, lifecycle allocation failure) and the debt entries; merged.

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.

3 participants