Skip to content

fix(libSceLibreSsl3): copy the EVP_MD_block_size digest field safely - #24394

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
domx4q:fix/libressl3-md-block-size-guest-pointers
Dec 4, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
domx4q:fix/libressl3-md-block-size-guest-pointers

Conversation

@domx4q

@domx4q domx4q commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What

EVP_MD_block_size in core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp read blockSize straight from the digest the caller passed. An unmapped digest pointer crashed the process.

It now picks the field offset as before: the libSceLibreSsl3 DigestMethod layout for EVP_sha1/EVP_sha224, and the parent EVP_MD layout for everything else. It then copies the 32-bit field in through GuestCopyIn_nid_no_patch. errno is saved and restored around the copy. An unreadable digest throws through NotImplementedAt_nid_no_patch. This is the same treatment the parent EVP_MD_size received in the merged EVP digest fix (5e108f0); libSceLibreSsl3's EVP_MD_size forwards to that parent export. A null digest still returns -1.

The digest is a guest pointer argument. Only EVP_sha1 and EVP_sha224 are matched by address, as before. Any other pointer, including one a game builds or corrupts, is read as an EVP_MD, so it goes through the checked copy.

For valid digests the result is unchanged: the existing checks for MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 in GuestLibreSsl3Digest.cpp still pass. No debt entry describes the old unchecked read, so there is no debt fragment.

Overlap

Tested

Arch Linux, GCC, Release, re-run on 2026-11-20 after rebasing onto main 0a025bd. guest_libressl3_digest (core/libs/tests/GuestLibreSsl3Digest.cpp) now also passes the unmapped address 0x10 to EVP_MD_block_size and checks that it throws and keeps errno.

Mutation check: with AdditionalExports.cpp reset to origin/main and the new check kept, guest_libressl3_digest segfaults.

ctest --test-dir build -R 'libressl3|public_headers' passed 159/159 (94 libSceLibreSsl3 tests, 65 public_headers*). tools/check_conventions.py --base origin/main passes. tools/guest_pointer_audit.py libSceLibreSsl3 no longer lists EVP_MD_block_size. tools/progress.py --module libSceLibreSsl3 gives 550/667 on both main and this branch.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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 (Claude Code)

EVP_MD_block_size read the block size straight from the guest digest.
Copy the field in through GuestCopyIn while preserving errno, at the
offset of the libSceLibreSsl3 or the parent digest layout, as the
parent EVP_MD_size does. An unreadable digest is rejected through
NotImplemented instead of being dereferenced. Results for valid digests
are unchanged.

@PrivacyOnion PrivacyOnion 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.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_icu_locale_core_tests built cleanly.
  • CTest (guest_icu_locale_core):
    1/1 Test #3981: guest_icu_locale_core ............   Passed    0.08 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceIcu/LocaleCore.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #3981: guest_icu_locale_core ............***Exception: SegFault  0.46 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified pointer safety and GuestCopyIn/GuestCopyOut usage in LocaleCore.cpp (ReadText, ReadStatus, WriteStatus, WriteResult) ensuring guest pointers cannot crash host or bypass protection
    • Verified uloc_getKeywordValue behavior and error status propagation with kIllegalArgument when locale/keyword are null or invalid
    • Verified uloc_getParent truncation and null termination semantics with u_terminateChars_nid_postfix and host staging buffer
    • Verified LP64 vs LLP64 portability and Windows/Linux guard page handling in GuestIcuLocaleCore.cpp
    • Verified strict AGENTS.md compliance regarding comments, debt tracking, and conventions mechanical gate pass

Looks Good To Me

@github-actions github-actions Bot added the prx label Nov 20, 2026
@domx4q
domx4q force-pushed the fix/libressl3-md-block-size-guest-pointers branch from 9340d5e to 4f61e97 Compare November 20, 2026 20:16
@domx4q

domx4q commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

A batch push at 16:38 UTC+1 put the wrong commit on this branch (9340d5e, the uloc change that is #24439). I restored the branch to the commit this PR is about: 4f61e97, fix(libSceLibreSsl3): copy the EVP_MD_block_size digest field safely (2 files, same content as before the bad push, clean on current main). The earlier approval was given on the wrong diff, so please take another look when you have time.

AI-assisted: yes (Claude Code)

@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 — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 4f61e976d90dddd4c964ff9def2eeb4a4079ef03. I read the prepared description, commit summary, manifest, diff, and both changed files; I also inspected the digest layouts, parent size export, and guest copy implementation. No commands or tests were run.

Results

Check Result Note
Changed code review passed Both changed files read
Tests not run Reported results are from the author
Negative control not run Author reports mutation check passed

Negative control

I did not run a negative control. The description reports that the test segfaults when the implementation is reset to origin/main while keeping the new assertion.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

I did not run the reported ctest, conventions check, guest pointer audit, build, or mutation check. Those results in the description are author-reported. No files were excluded from the review bundle; both files listed as reviewed in the manifest were read.

To get this to a good state

Nothing is required. The reported checks and mutation result are optional context; no additional action is required for this review.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 4f61e976d9, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#18156, #21208, #22013, #22795, #23226, #23385, #24324, #24533, #24582, #24690, #24693, #17553, #19619, #20085, #21081, #19682, #22123, #22529, #22572, #22662, #23479, #23787, #24568, #15330, #21249, #21630, #21713, #22040, #23490). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_libressl3_digest (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6540 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #17553 (guest_memory); none is in this PR's area. The 2143 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@Helldiverr

Copy link
Copy Markdown
Contributor

On Windows, head 4f61e976d9 merged onto main dad6acd1b8 passes the 4 digest and EVP tests 4/4 times. The PR's test against main's AdditionalExports.cpp segfaults with a read of 0x74. Of five mutations, 4 are caught; the one that survives removes the errno restore.

Existing runs:

  • PrivacyOnion approved after a Linux run against 9340d5e2e4. The author later explained that this was the wrong commit, pushed by mistake, and restored the branch to 4f61e976d9.
  • MarcZX10 read the restored head and ran nothing.
  • kiwe147 ran it on Windows in a 30-PR batch applied to main fd4aeed483, where guest_libressl3_digest passes.

What this run adds. The first run of this PR's own diff by itself, with a negative control and mutations. It is on main dad6acd1b8, which includes #26161.

Code.

  • The save and restore at AdditionalExports.cpp:162 and :164 are the pattern that refactor(libressl3): drop errno saves around guest copies #26161 (refactor(libressl3): drop errno saves around guest copies) removed from libSceLibreSsl3 on main. Removing the restore (mA below) leaves the PR's errno == 71 check at GuestLibreSsl3Digest.cpp:69 passing, so GuestCopyIn_nid_no_patch already keeps errno on this path. Lines 162 and 164 and the <cerrno> include could go. main also has GuestPtr<T>::CopyIn (GuestPtr.hpp:20-22 at dad6acd1b8), which refactor(libressl3): drop errno saves around guest copies #26161 uses for the same kind of copy in Key.cpp.
  • An unreadable md goes to NotImplementedAt_nid_no_patch at line 165, as Key.cpp does on main (Key.cpp:247-248 at dad6acd1b8). That path also increments the not-implemented counter and calls LibcRunReportMissingFunction_nid_no_patch (General.cpp:1245-1246 at dad6acd1b8). As a result, a bad pointer from a title is reported as a missing EVP_MD_block_size. sk_push in Stack.cpp throws std::invalid_argument for the same situation. Either way the test passes, because it catches std::exception.
  • LibreSsl3::DigestMethod and EvpMd declare the same fields in the same order up to blockSize, so both arms of the ternary at lines 158-160 give offset 0x64. The negative control's read of 0x74, which is 0x10 + 0x64, matches that.
  • py -3 tools/check_conventions.py --base dad6acd1b8 on the merge prints All conventions checks passed. tools/debt_fold.py --check exits 1, but only because of two libSceRudp fragments that conflict on main dad6acd1b8 itself. This PR adds no fragment.

Negative control and mutation. These ran on the merge. The mutations were applied to AdditionalExports.cpp.

  • Negative control: main's file with the PR's test segfaults (0xc0000005, read of 0x0000000000000074).
  • mA: errno = savedErrno; is removed. Survives.
  • mB: if (!copied) return 0;. Caught at GuestLibreSsl3Digest.cpp:71.
  • mC: the EvpMd arm reads contextSize. Caught at line 57 (MD5).
  • mD: the DigestMethod arm reads digestSize. Caught at line 58 (SHA-1).
  • mE: errno = 22 is set before NotImplementedAt_nid_no_patch. Caught at line 71.

Tests.

tests main dad6acd1b8 merge 01155ba66a
guest_libressl3_digest pass (old test) pass 4/4
guest_libressl3_digest_names pass pass 4/4
guest_libressl3_digest_context pass pass 4/4
guest_libressl3_evp pass pass 4/4
guest_libressl3_digest, negative control SegFault, read of 0x74
guest_libressl3_digest, mutations 4 of 5 caught; mA (errno restore) survives

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head 4f61e976d9, merged onto main dad6acd1b8 as 01155ba66a

main has since moved 60 commits to 7a0de821ab, none of them in the files cited here, and the head still merges cleanly.

AI-assisted: yes

@ligmaSec ligmaSec 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.

Built the changed digest unit and ran the branch's GuestLibreSsl3Digest fixture against the existing Linux runtime. It passed. The change reads the block-size field through the checked copy while preserving the existing result for readable digest objects.

AI-assisted: yes.

@github-actions

github-actions Bot commented Dec 3, 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 21692 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
PR 21702 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp
PR 21706 core/libs/prx/libSceLibreSsl3/AdditionalExports.cpp

@oneandonlydean
oneandonlydean merged commit 79293c2 into boykopovar:main Dec 4, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants