fix(libc): validate DWARF CIE/FDE and CFI instruction bounds in Unwind #25204
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25204"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by gurtgg on 2026-11-21T19:24:53Z.
What
.eh_frameparsing incore/libs/prx/libc/include/exceptions/Unwind.hpp(Read,Uleb,Sleb,Encoded,DecodeRange,Instructions) and updatecore/libs/prx/libc/src/exception/Unwind.cpp(IndexFrames) andcore/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp(DwarfFrames) to pass and enforcefdeEnd/ section bounds.DW_CFA_def_cfa_expression,DW_CFA_expression,DW_CFA_val_expression,DW_CFA_advance_loc4) instead of reading past the FDE or section end.Tested
guest_app_archive(core/libs/tests/GuestAppArchive.cpp): covers truncated CIE/FDE records, truncated CFI expressions andDW_CFA_advance_loc4payloads, and valid minimal CIE/FDE decoding producing expectedFrameandRules.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T19:36:27Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c04eb60949:tools/check_conventions.pypassed.guest_app_archive_testsbuilt cleanly.guest_app_archive_present,guest_app_archive_absent,guest_app_archive_damaged,guest_app_archive_invalid):core/libs/prx/libc/include/exceptions/Unwind.hppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T00:01:40Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: cap the FDE record length to its enclosing record bounds before deriving
frame.end.What I ran
Reviewed head
c04eb60949a7821fd1520776858dd612486246fe. No commands or tests were run; the reader review tools were used.Results
Findings
Blocking
core/libs/prx/libc/include/exceptions/Unwind.hpp:212:frame.endis computed asp + lengthbefore checking that the declared FDE length fits within the containing.eh_framerange.TryReadthen only validates against this derived end, so a malformed length extending beyond the section can still letDecodeRangeread beyond the section. Pass the section end into the decoder or otherwise validate the record extent before using it as a bound.Non-blocking
None.
Not verified
Tests and runtime behavior were not run. Reviewed changed files:
core/libs/prx/libc/include/exceptions/Unwind.hpp,core/libs/tests/GuestAppArchive.cpp. Both files listed as reviewed were read; no excluded changed files were listed.To get this to a good state
Validate the FDE record length against the containing section boundary, then rerun the bounds regression tests including a record whose length exceeds that boundary.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T00:25:15Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: prevent malformed section bounds from being dereferenced before validation in
DecodeRange.What I ran
62eb0d343e61158a1f3682f6074f38bd27126595and the prepared diff; no build or tests were run.core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp,core/libs/prx/libc/include/exceptions/Unwind.hpp,core/libs/prx/libc/src/exception/Unwind.cpp, andcore/libs/tests/GuestAppArchive.cpp.Results
Findings
Blocking
DecodeRangereads the FDE length with unboundedReadbefore checking thatfdeEndhas at least four bytes available. A non-nullquery.fdewith fewer than four bytes beforequery.fdeEndcauses the length read to overrun the supplied section. Check available bytes before reading. (core/libs/prx/libc/include/exceptions/Unwind.hpp:213)Non-blocking
None.
Not verified
files.jsonwere not present in the review manifest; not verified.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:10:45Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: pass a bounded end pointer for FDE decoding in the non-Windows path, which still decodes records with unbounded reads.
What I ran
Reviewed head
04e903d18434298817e034e8ecabab41298c9f41. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libc/src/exception/Unwind.cpp:259:DecodeCandidatecallsDecodeRangewithqueryas supplied, and the non-Windows lookup path does not populatefdeEnd. Consequently,DecodeRangetakes its legacyReadbranches for the FDE and CIE lengths (Unwind.hpp:213-230) and does not bound CIE augmentation or FDE instructions. Malformed.eh_framedata reaching this path can still trigger out-of-bounds reads, contrary to the fix's stated goal. Thread the section end through the non-Windows lookup and candidate decode path, and ensure later augmentation and instruction parsing use record ends.Non-blocking
None.
Not verified
No files were excluded by rule. Reviewed the complete changed files
StackWalk.hpp,Unwind.hpp,Unwind.cpp, andGuestAppArchive.cpp; read the change description, commit list, manifest, and full diff. Tests and runtime behavior were not verified.To get this to a good state
Bound the non-Windows
.eh_framelookup and decode path with the section end, then add coverage for malformed records through that path and rerun the relevant tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:11:56Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: make the AgcDriver stack walker validate FDE augmentation data against the record end before advancing the instruction pointer.
What I ran
Reviewed head
4a05898886a84748f729343261d3bca623e69d4dusing the prepared diff andrepo_read.py. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp:108:find()reads the FDE augmentation length withUleb(p)and advancesp += sizewithout checking either read against the decodedframe.end. A malformed FDE can therefore make this stack-walking path read past the FDE, despite the new bounds-checkedDecodeFdeAugmentationhelper used inUnwind.cpp. Use the bounded helper and reject failure before settingframe.begin.Non-blocking
None.
Not verified
No build, test execution, or platform runtime behavior was verified. All changed files were included and read:
StackWalk.hpp,Unwind.hpp,Unwind.cpp, andGuestAppArchive.cpp. No changed files were excluded.To get this to a good state
Use the bounded FDE augmentation decoder in
DwarfFrames::find(), then rerun the relevant tests and build on the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:24:17Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: pass the stack-walk frame section start as the CIE lower bound in both
DecodeRangecalls.What I ran
Reviewed head
41f43758b28bbf929db5c8c97b290adf541aed5fusing the prepared diff and the pinned reader. No executable commands or tests were run.Results
Negative control
Not run.
Findings
Blocking
core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp:36: The index-buildingDecodeRangecall suppliesframesEndbut leavesfdeBeginnull. A malformed FDE can therefore point its CIE offset before theframessection;DecodeRangechecks that the CIE is belowfdeEnd, but withoutfdeBeginit does not reject that lower out-of-section pointer before reading it. Passframesas the finalLookupbound here and in the corresponding call at line 105.Non-blocking
None.
Sources
Not verified
No tests or builds were run. All four changed files were reviewed, but only selected ranges were read from
Unwind.hppandUnwind.cpp; the remainder of those files and the final 36 lines ofStackWalk.hppwere not read.GuestAppArchive.cppwas read in full.To get this to a good state
Pass the
frameslower bound to bothDecodeRangecalls inStackWalk.hpp, then rerun the unwind bounds tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T14:57:50Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve and use the CIE’s LSDA encoding when decoding FDE augmentation in the stack walker.
What I ran
Reviewed head
e193d08327d363de767c905a615f885e365d005dand the prepared diff. No commands or tests were run; repository reading usedrepo_read.py.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp:107:find()callsDecodeFdeAugmentationwith LSDA encoding255, which means “no LSDA.” For azLCIE, this skips decoding the LSDA address and advances to the end of the augmentation payload. The LSDA bytes can then be interpreted as CFI instructions, causing stack unwinding to fail or use incorrect rules for frames with LSDA data. Preserve thelsdaEncodingreturned byDecodeRangeand pass it toDecodeFdeAugmentation.Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp,core/libs/prx/libc/include/exceptions/Unwind.hpp,core/libs/prx/libc/src/exception/Unwind.cpp, andcore/libs/tests/GuestAppArchive.cpp.files.jsonand behavior on target hardware were not inspected or verified.To get this to a good state
DecodeFdeAugmentationin the stack walker, then add or run coverage for azLFDE with LSDA data.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T20:51:07Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: bound all CIE parsing to the containing section end.
What I ran
Reviewed head
d8d639900930642be550c0b986eb110c8df487ebfrom the prepared diff and source files. I did not run commands or tests.Results
guest_app_archivecoverageFindings
Blocking
DecodeRangechecks that the CIE starts at or afterfdeBegin, but whenfdeEndis provided it uses that upper limit for the CIE length read and content bounds. In.eh_framelayouts, the referenced CIE precedes the FDE; a malformed CIE length can therefore extend past its containing section end and still pass validation, allowing later CIE parsing to read beyond the section. Carry a distinct CIE section end (or otherwise validate the CIE length against the actual section boundary), and use it for the CIE header, augmentation, and instruction bounds.core/libs/prx/libc/include/exceptions/Unwind.hpp:267Non-blocking
None.
Not verified
guest_app_archivetests or other builds.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T23:28:16Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent
DecodeRangefrom dereferencing an unterminated augmentation string outside the bounded CIE.What I ran
Head reviewed:
5ceba4ee9411a831054e2e3c059eb9aab4934eb7. No build or tests were run; source inspection usedrepo_read.pyon the prepared bundle and repository at the pinned head.Results
Findings
Blocking
core/libs/prx/libc/include/exceptions/Unwind.hpp:313: The CIE augmentation string is bounded while scanning for its NUL terminator, but later*augmentationand the loop overaugmentation + 1treat it as a valid C string. If the string is unterminated withinframe.cieEnd, the loop can read past the CIE and its containing section. Keep augmentation parsing bounded by the validated CIE range and reject a missing terminator before inspecting its contents.Non-blocking
None.
Not verified
reviewedin the manifest:StackWalk.hpp,StackWalk.cpp,Unwind.hpp,Unwind.cpp, andGuestAppArchive.cpp. The manifest lists no excluded changed files.To get this to a good state
Bound all augmentation-string accesses to the CIE and reject an unterminated string; then rerun the relevant tests and build.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T00:22:19Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject overflowing LEB128 operands before using them as decoded values.
What I ran
Reviewed head
a325b7d56320c301a9f3ebafd42f06eef86e5436from the prepared diff and pinned reader. No test or build command was run.Results
Findings
Blocking
core/libs/prx/libc/include/exceptions/Unwind.hpp:141andcore/libs/prx/libc/include/exceptions/Unwind.hpp:163:TryUleb/TrySlebcan accept overflowing final payload bits. For a 64-bit word, the tenth ULEB byte may contribute only one data bit, but the implementation shifts all seven bits at offset 63; similarly, signed LEB’s final payload is not checked for valid sign-extension bits. Malformed CIE/CFI operands can therefore be accepted with truncated values instead of being rejected. Validate the permitted high bits in the last byte before shifting/returning, and add malformed overflow cases.Non-blocking
None.
Not verified
StackWalk.hpp,StackWalk.cpp,Unwind.hpp,Unwind.cpp,GuestAppArchive.cpp, plus the prepared description, commits, manifest, and diff. All five changed files are listed as included in the manifest; no excluded changed files were listed.To get this to a good state
Reject overflowing ULEB/SLEB values and add regression coverage for both malformed encodings. Then run the relevant test/build checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T01:58:58Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: use the section’s effective size when setting the
.ehframbounds on Windows.What I ran
Reviewed head
b98b8ad85f6e4a9e2df0645446ba5e221cabdd7c. Read the prepared description, commits, diff, manifest, and all five changed files through the pinned reader. No build or tests were run.files.jsonwas not available through the reader; the reader’s file listing confirms all five changed files are included.Results
Findings
Blocking
.ehframbounds are set usingsection.Misc.VirtualSizedirectly (core/libs/prx/libc/src/exception/Unwind.cpp:648). WhenVirtualSizeis zero butSizeOfRawDatais nonzero, this setsfdeEndandcieEndtoframes, soDecodeRangerejects valid frame records. The newSectionBoundsForcode already usesVirtualSizewith aSizeOfRawDatafallback (core/libs/prx/libc/src/exception/Unwind.cpp:743in the diff). Apply the same effective-size calculation when indexing and decoding.ehframsections.Non-blocking
None.
Not verified
Build and test results were not verified. The review bundle listed all changed files as included, and each was read.
files.jsonwas not readable through the available reader interface.To get this to a good state
Use the effective section size for
.ehframindexing and bounds, then rerun the relevant Windows build and tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T01:54:36Z.
Review: APPROVED
Reviewed — looks good
The bounds checks appear sound in the changed paths; all five changed files were read, but no tests were run in this review.
What I ran
Read the prepared diff and all changed files at head
5feceb128431f1363b4853dc37bf2209d8de4bebusingrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior and the author-reported
guest_app_archivetest were not independently verified. No files were excluded by the review manifest; all changed files were read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T02:02:13Z.
Review: COMMENTED
Actionable comments posted: 4
2d6c9e4c-0639-4a91-b5f7-612ba249ce0aReviewing files that changed from the base of the PR and between
e3ad7b845dand5feceb1284.core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hppcore/libs/prx/libSceAgcDriver/tests/StackWalk.cppcore/libs/prx/libc/include/exceptions/Unwind.hppcore/libs/prx/libc/src/exception/Unwind.cppcore/libs/tests/GuestAppArchive.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T13:44:45Z.
Review: COMMENTED
7ee762d7-f056-430b-ada0-cad18143eb64Reviewing files that changed from the base of the PR and between
5feceb1284and7a1c1f8d59.core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hppcore/libs/prx/libSceAgcDriver/tests/StackWalk.cppcore/libs/prx/libc/include/exceptions/Unwind.hppcore/libs/tests/GuestAppArchive.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T13:53:31Z.
Review: APPROVED
Reviewed — looks good
The bounds checks and malformed-record tests look sound in the inspected changes at head
7a1c1f8d5967b95cf024eb99dd35828fe95d3bf8; no test command was run.What I ran
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/include/StackWalk.hpp,core/libs/prx/libSceAgcDriver/tests/StackWalk.cpp,core/libs/prx/libc/include/exceptions/Unwind.hpp,core/libs/prx/libc/src/exception/Unwind.cpp, andcore/libs/tests/GuestAppArchive.cpp.files.json(not present in the reader listing); all five changed files were listed as included and read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:49:53Z.
Review: COMMENTED
The new end checks cover the bytes of an encoded field. For indirect encodings,
TryEncodedsubsequently loads from the decoded address, which is outside those checks. Disabling LSDA resolution for the AGC stack walker narrows that path, but the normal unwinder still resolves indirect values. Please clarify the boundary of this hardening and validate indirect reads against readable mappings wherever the unwinder resolves them.Source review at
7a1c1f8d59. The head merges cleanly onto484e8e6b77in a trial merge. The stack-walk and archive checks are pending.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.