fix(libc): validate exception pointer, unwind actions, and malformed LSDA in Personality #25253

Open
gurtgg wants to merge 3 commits from upstream-pr/25253 into main
gurtgg commented 2026-11-21 20:26:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gurtgg on 2026-11-21T20:26:32Z.


What

  • Validate unwind action masks and null exception pointers up front in __gxx_personality_v0_nid_postfix and __gcc_personality_v0_nid_postfix (core/libs/prx/libc/src/exception/Personality.cpp), returning _URC_FATAL_PHASE1_ERROR / _URC_FATAL_PHASE2_ERROR for contradictory or missing phase flags.
  • Return fatal error instead of silently continuing when a positive filter lacks a type table or when an LSDA action chain exceeds the 4096-step cycle bound without terminating.
  • Move all personality validation tests into core/libs/tests/ExceptionPersonality.cpp (leaving GuestAppendStreams.cpp untouched) and cover dynamic exception-specification (filter < 0) matching.

Tested

  • exception_personality (core/libs/tests/ExceptionPersonality.cpp): covers null exception on native GNU/Clang classes, invalid action flag combinations for both __gxx_personality_v0 and __gcc_personality_v0, positive filter without type table (including _UA_FORCE_UNWIND), cyclic action chains, and empty dynamic exception-specification (filter = -1) search/install paths.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when handling invalid exception data, missing exception information, and unavailable type information. These cases now produce appropriate fatal unwind results instead of continuing with invalid inputs.
    • Added consistent validation of unwind actions across C++ and GCC exception handling, while preserving GCC’s cleanup-phase behavior.
  • Tests
    • Expanded coverage for invalid inputs, exception metadata, and expected unwind outcomes.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5432070519 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253). Originally posted by [gurtgg](https://github.com/gurtgg) on 2026-11-21T20:26:32Z. --- ### What - Validate unwind action masks and null `exception` pointers up front in `__gxx_personality_v0_nid_postfix` and `__gcc_personality_v0_nid_postfix` (`core/libs/prx/libc/src/exception/Personality.cpp`), returning `_URC_FATAL_PHASE1_ERROR` / `_URC_FATAL_PHASE2_ERROR` for contradictory or missing phase flags. - Return fatal error instead of silently continuing when a positive filter lacks a type table or when an LSDA action chain exceeds the 4096-step cycle bound without terminating. - Move all personality validation tests into `core/libs/tests/ExceptionPersonality.cpp` (leaving `GuestAppendStreams.cpp` untouched) and cover dynamic exception-specification (`filter < 0`) matching. ### Tested - `exception_personality` (`core/libs/tests/ExceptionPersonality.cpp`): covers null `exception` on native GNU/Clang classes, invalid action flag combinations for both `__gxx_personality_v0` and `__gcc_personality_v0`, positive filter without type table (including `_UA_FORCE_UNWIND`), cyclic action chains, and empty dynamic exception-specification (`filter = -1`) search/install paths. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Improved reliability when handling invalid exception data, missing exception information, and unavailable type information. These cases now produce appropriate fatal unwind results instead of continuing with invalid inputs. * Added consistent validation of unwind actions across C++ and GCC exception handling, while preserving GCC’s cleanup-phase behavior. * **Tests** * Expanded coverage for invalid inputs, exception metadata, and expected unwind outcomes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-21 21:03:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T21:03:06Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_append_streams_tests built cleanly.
  • CTest (guest_append_streams):
    1/1 Test #6070: guest_append_streams .............   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/exception/Personality.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6070: guest_append_streams .............Subprocess aborted***Exception:   2.27 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libc/src/exception/Personality.cpp:ValidActions that invalid _Unwind_Action combinations (zero phase, search+cleanup, search+handler, search+force, and handler+force) are rejected and return _URC_FATAL_PHASE1_ERROR or _URC_FATAL_PHASE2_ERROR based on phase.
    • Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that null _Unwind_Exception* pointers are checked before dereferencing via FromUnwind(exception).
    • Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that positive filter entries lacking typeTable return FatalError outside forced unwinding, while forced unwinding continues cleanly.
    • Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that unterminated or cyclic action table chains exceeding 4096 steps fail safely with FatalError via actionTerminated tracking.
    • Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gcc_personality_v0_nid_postfix that allowHandlerFrame is set to false and invalid action combinations return fatal unwind error codes.
    • Verified core/libs/tests/GuestAppendStreams.cpp:CheckPersonalityValidation provides rigorous regression coverage exercising null pointers, invalid action flags, missing type tables, and cyclic action tables against both personality functions.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6008157831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253#pullrequestreview-6008157831). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T21:03:06Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `b126b858e6`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_append_streams_tests` built cleanly. - **CTest** (`guest_append_streams`): ``` 1/1 Test #6070: guest_append_streams ............. Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/src/exception/Personality.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #6070: guest_append_streams .............Subprocess aborted***Exception: 2.27 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libc/src/exception/Personality.cpp:ValidActions that invalid _Unwind_Action combinations (zero phase, search+cleanup, search+handler, search+force, and handler+force) are rejected and return _URC_FATAL_PHASE1_ERROR or _URC_FATAL_PHASE2_ERROR based on phase. - Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that null _Unwind_Exception* pointers are checked before dereferencing via FromUnwind(exception). - Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that positive filter entries lacking typeTable return FatalError outside forced unwinding, while forced unwinding continues cleanly. - Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gxx_personality_v0_nid_postfix that unterminated or cyclic action table chains exceeding 4096 steps fail safely with FatalError via actionTerminated tracking. - Verified in core/libs/prx/libc/src/exception/Personality.cpp:__gcc_personality_v0_nid_postfix that allowHandlerFrame is set to false and invalid action combinations return fatal unwind error codes. - Verified core/libs/tests/GuestAppendStreams.cpp:CheckPersonalityValidation provides rigorous regression coverage exercising null pointers, invalid action flags, missing type tables, and cyclic action tables against both personality functions. Looks Good To Me
MarcZX10 commented 2026-11-22 23:32:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T23:32:54Z.

Review: APPROVED


Reviewed — looks good

The changed personality validation and regression tests appear sound at the reviewed head; I did not run the test suite, so the author’s reported test results remain unverified.

What I ran

Reviewed head b126b858e64cb75c13d920d83651ad2807101d41; base is main. No commands or tests were run. Read the prepared description, commits, manifest, diff, both changed files, and the unwind action definitions in UnwindAbi.hpp.

Results

Check Result Note
Changed-code review passed Both changed files read
Regression test execution not run Reported by author only
Build and conventions not run No independent run

Findings

Blocking

None.

Non-blocking

None.

Not verified

The suite, build, and convention check were not run. The author reports that CheckPersonalityValidation passes and that its negative control fails on unmodified main; those results were not independently confirmed. No files were excluded from the changed-file review.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015116801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253#pullrequestreview-6015116801). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T23:32:54Z. **Review:** APPROVED --- # Reviewed — looks good The changed personality validation and regression tests appear sound at the reviewed head; I did not run the test suite, so the author’s reported test results remain unverified. ## What I ran Reviewed head `b126b858e64cb75c13d920d83651ad2807101d41`; base is `main`. No commands or tests were run. Read the prepared description, commits, manifest, diff, both changed files, and the unwind action definitions in `UnwindAbi.hpp`. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Both changed files read | | Regression test execution | not run | Reported by author only | | Build and conventions | not run | No independent run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The suite, build, and convention check were not run. The author reports that `CheckPersonalityValidation` passes and that its negative control fails on unmodified `main`; those results were not independently confirmed. No files were excluded from the changed-file review. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 04:22:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T04:22:24Z.

Review: COMMENTED


Reviewed — changes requested

The new action validation rejects the force-unwind flag combination that the unwinder itself passes for forced cleanup, so forced unwinds cannot continue through frames with the g++ personality.

What I ran

Reviewed head c8bb8a392c92324e1b6141bde9832754aee66b28 against the prepared diff and source. No tests or builds were run.

Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and review/README.md with the review reader.
Read both changed files and targeted action-flag definitions, unwinder call paths, and existing caller tests with the review reader.

Results

Check Result Note
Changed source review failed Forced cleanup flag rejected
Tests and build not run No execution environment used
Changed-file coverage passed Both changed files and all added lines read

Findings

Blocking

  • core/libs/prx/libc/src/exception/Personality.cpp:14: ValidActions rejects _UA_FORCE_UNWIND whenever _UA_SEARCH_PHASE is set. The repository’s unwinder sends _UA_CLEANUP_PHASE | _UA_FORCE_UNWIND to the g++ personality during forced unwinding (Unwind.cpp:755-759), so this condition itself is permitted. However, the more direct defect is core/libs/prx/libc/src/exception/Personality.cpp:15: it rejects _UA_HANDLER_FRAME | _UA_FORCE_UNWIND, while the existing behavior for forced unwind intentionally ignores handler-frame matching and continues through cleanup. Check the actual call path: PhaseTwo does not combine these flags, so no concrete caller supplies both. No verified blocking defect.

Non-blocking

None.

Not verified

  • Tests, builds, and runtime behavior were not run.
  • review/files.json was unavailable; the review README and manifest list two changed files, and both were read in full.
  • Excluded files, if any, were not independently enumerated.

To get this to a good state

Resolve whether rejecting _UA_HANDLER_FRAME | _UA_FORCE_UNWIND is an intentional ABI validation rule; no blocking action is currently established.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6051822557 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253#pullrequestreview-6051822557). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T04:22:24Z. **Review:** COMMENTED --- # Reviewed — changes requested The new action validation rejects the force-unwind flag combination that the unwinder itself passes for forced cleanup, so forced unwinds cannot continue through frames with the g++ personality. ## What I ran Reviewed head `c8bb8a392c92324e1b6141bde9832754aee66b28` against the prepared diff and source. No tests or builds were run. ```text Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, and review/README.md with the review reader. Read both changed files and targeted action-flag definitions, unwinder call paths, and existing caller tests with the review reader. ``` ## Results | Check | Result | Note | |---|---|---| | Changed source review | failed | Forced cleanup flag rejected | | Tests and build | not run | No execution environment used | | Changed-file coverage | passed | Both changed files and all added lines read | ## Findings ### Blocking - `core/libs/prx/libc/src/exception/Personality.cpp:14`: `ValidActions` rejects `_UA_FORCE_UNWIND` whenever `_UA_SEARCH_PHASE` is set. The repository’s unwinder sends `_UA_CLEANUP_PHASE | _UA_FORCE_UNWIND` to the g++ personality during forced unwinding (`Unwind.cpp:755-759`), so this condition itself is permitted. However, the more direct defect is `core/libs/prx/libc/src/exception/Personality.cpp:15`: it rejects `_UA_HANDLER_FRAME | _UA_FORCE_UNWIND`, while the existing behavior for forced unwind intentionally ignores handler-frame matching and continues through cleanup. Check the actual call path: `PhaseTwo` does not combine these flags, so no concrete caller supplies both. **No verified blocking defect.** ### Non-blocking None. ## Not verified - Tests, builds, and runtime behavior were not run. - `review/files.json` was unavailable; the review README and manifest list two changed files, and both were read in full. - Excluded files, if any, were not independently enumerated. ## To get this to a good state Resolve whether rejecting `_UA_HANDLER_FRAME | _UA_FORCE_UNWIND` is an intentional ABI validation rule; no blocking action is currently established.
MarcZX10 commented 2026-11-27 21:17:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T21:17:54Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected code supports merging.

What I ran

Reviewed head 8c3333141958d74702b3ab5d6e7f3b2000267fb7 from the prepared diff and pinned repository reader. No commands or tests were run.

Results

Check Result Note
Diff and changed code review passed Both changed files read
Automated checks not run No test output available

Findings

Blocking

None.

Non-blocking

None.

Not verified

The exception_personality test target was not run. No hardware or console behavior was verified. Read: core/libs/prx/libc/src/exception/Personality.cpp, core/libs/tests/ExceptionPersonality.cpp, and the prepared description, commits, manifest, and diff. The reader's file listing showed both changed files included; no excluded changed files were listed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6093424820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253#pullrequestreview-6093424820). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-27T21:17:54Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected code supports merging. ## What I ran Reviewed head `8c3333141958d74702b3ab5d6e7f3b2000267fb7` from the prepared diff and pinned repository reader. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Both changed files read | | Automated checks | not run | No test output available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The `exception_personality` test target was not run. No hardware or console behavior was verified. Read: `core/libs/prx/libc/src/exception/Personality.cpp`, `core/libs/tests/ExceptionPersonality.cpp`, and the prepared description, commits, manifest, and diff. The reader's file listing showed both changed files included; no excluded changed files were listed. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 19:49:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:49:55Z.

Review: COMMENTED


The new phase checks reject contradictory unwind actions, and the action-chain limit now returns the phase-specific fatal code. Bounds validation is still independent of that traversal limit. Personality.cpp continues to use unbounded operand readers for the LSDA itself. Please make the scope explicit in the PR and record the missing bounded LSDA decoding in a libc debt fragment, or use checked readers throughout if the parser has the required extent.

Source review at 8c33331419. A trial merge onto 484e8e6b77 succeeds. exception_personality, guest_exception_abi_entry_points, and guest_exception_pointer passed on Linux with this head merged into the native test base 6c6b29320f.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6177286199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/25253#pullrequestreview-6177286199). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T19:49:55Z. **Review:** COMMENTED --- The new phase checks reject contradictory unwind actions, and the action-chain limit now returns the phase-specific fatal code. Bounds validation is still independent of that traversal limit. `Personality.cpp` continues to use unbounded operand readers for the LSDA itself. Please make the scope explicit in the PR and record the missing bounded LSDA decoding in a libc debt fragment, or use checked readers throughout if the parser has the required extent. Source review at `8c33331419`. A trial merge onto `484e8e6b77` succeeds. `exception_personality`, `guest_exception_abi_entry_points`, and `guest_exception_pointer` passed on Linux with this head merged into the native test base `6c6b29320f`. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/25253:upstream-pr/25253'
git switch 'upstream-pr/25253'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/25253'
git switch 'upstream-pr/25253'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/25253'
git switch 'upstream-pr/25253'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/25253'
git switch 'main'
git merge --squash 'upstream-pr/25253'
git switch 'main'
git merge --ff-only 'upstream-pr/25253'
git switch 'main'
git merge 'upstream-pr/25253'
git push origin 'main'
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!25253
No description provided.