revert: fix libressl3 aes wrap unwrap length bounds (#23208) #23365

Merged
oneandonlydean merged 1 commit from upstream-pr/23365 into main 2026-11-18 23:13:36 +00:00
oneandonlydean commented 2026-11-18 22:50:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-11-18T22:50:14Z.


What

Exact inverse revert of #23208 (merge 0083a34a19). Since it merged, guest_libressl3_aes and guest_libressl3_aes_wrap fail on Windows main, on plain main as well: LibreSSL3 AES wrap check failed at line 151 and LibreSSL3 AES_unwrap_key check failed at line 171, then exit 0xc0000409. #23208 is the only recent change to Aes.cpp and AesWrap.cpp, the code both checks run through. The length bounds can come back once both tests pass on Windows with them.

Tested

The full Windows suite on this PR must show guest_libressl3_aes and guest_libressl3_aes_wrap passing.

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:5385437094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23365). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-11-18T22:50:14Z. --- ### What Exact inverse revert of #23208 (merge 0083a34a19). Since it merged, `guest_libressl3_aes` and `guest_libressl3_aes_wrap` fail on Windows main, on plain main as well: `LibreSSL3 AES wrap check failed at line 151` and `LibreSSL3 AES_unwrap_key check failed at line 171`, then exit 0xc0000409. #23208 is the only recent change to `Aes.cpp` and `AesWrap.cpp`, the code both checks run through. The length bounds can come back once both tests pass on Windows with them. ### Tested The full Windows suite on this PR must show `guest_libressl3_aes` and `guest_libressl3_aes_wrap` passing. ### Checklist - [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-18 22:51:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T22:51:26Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libressl3_aes_ccm_tests built cleanly.
  • CTest (guest_libressl3_aes_ccm):
    1/1 Test #4433: guest_libressl3_aes_ccm ..........   Passed    0.50 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibreSsl3/src/Aes.cpp, core/libs/prx/libSceLibreSsl3/src/AesWrap.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4433: guest_libressl3_aes_ccm ..........   Passed    0.50 sec
    100% tests passed, 0 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified AES_unwrap_key_nid_postfix in core/libs/prx/libSceLibreSsl3/src/Aes.cpp: confirmed reversion to upstream LibreSSL length validation ((length & 0x7) || length < 24) matches upstream aes_wrap.c and LibreSSL specification
    • Verified AES_wrap_key_nid_postfix in core/libs/prx/libSceLibreSsl3/src/AesWrap.cpp: confirmed (inlen < 16 || (inlen & 7) != 0) without arbitrary INT_MAX - 8 cap aligns with upstream implementation
    • Verified pointer validation and memory safety in both Aes.cpp and AesWrap.cpp: CopyIn, CopyOut, CopyInChunks, and CopyOutChunks properly guard guest pointers and throw std::invalid_argument on null/unreadable/unwritable addresses
    • Checked integer overflow and signed conversion safety: return static_cast(inlen + 8) and static_cast(length) remain safe for standard key wrap buffer sizes under realistic guest memory layouts
    • Verified test suite changes in core/libs/prx/libSceLibreSsl3/tests/AesCcm.cpp: removal of CheckKeyWrapBounds cleans up tests asserting non-standard bounds while guest_libressl3_aes_ccm continues to pass cleanly

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5966475548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23365#pullrequestreview-5966475548). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T22:51:26Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b410274d06`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libressl3_aes_ccm_tests` built cleanly. - **CTest** (`guest_libressl3_aes_ccm`): ``` 1/1 Test #4433: guest_libressl3_aes_ccm .......... Passed 0.50 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibreSsl3/src/Aes.cpp`, `core/libs/prx/libSceLibreSsl3/src/AesWrap.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4433: guest_libressl3_aes_ccm .......... Passed 0.50 sec 100% tests passed, 0 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified AES_unwrap_key_nid_postfix in core/libs/prx/libSceLibreSsl3/src/Aes.cpp: confirmed reversion to upstream LibreSSL length validation ((length & 0x7) || length < 24) matches upstream aes_wrap.c and LibreSSL specification - Verified AES_wrap_key_nid_postfix in core/libs/prx/libSceLibreSsl3/src/AesWrap.cpp: confirmed (inlen < 16 || (inlen & 7) != 0) without arbitrary INT_MAX - 8 cap aligns with upstream implementation - Verified pointer validation and memory safety in both Aes.cpp and AesWrap.cpp: CopyIn, CopyOut, CopyInChunks, and CopyOutChunks properly guard guest pointers and throw std::invalid_argument on null/unreadable/unwritable addresses - Checked integer overflow and signed conversion safety: return static_cast<int>(inlen + 8) and static_cast<int>(length) remain safe for standard key wrap buffer sizes under realistic guest memory layouts - Verified test suite changes in core/libs/prx/libSceLibreSsl3/tests/AesCcm.cpp: removal of CheckKeyWrapBounds cleans up tests asserting non-standard bounds while guest_libressl3_aes_ccm continues to pass cleanly 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!23365
No description provided.