fix(relinker): enforce DWARF CFI bounds, register rules and landing pad checks #12910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12910"
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 slopgobblercobbler on 2026-10-29T14:02:48Z.
What
Audits and enforces DWARF Call Frame Information (
.eh_frame) validation inRelinker::UnusedNidFilter::EhFrameReader:%rip/ return address (RA) per System V AMD64 psABI section 3.7 Figure 3.36 for x86-64 console binaries).S(signal frame) markers cleanly without demanding extra payload bytes, and skips trailing augmentation bytes up toaugmentationEndper LSB specifications.DW_EH_PE_udata2,DW_EH_PE_udata4) against 64-bit integer overflow, while permittingDW_EH_PE_uleb128,DW_EH_PE_udata8, andDW_EH_PE_absptrto wrap modulo 2^64 for backward displacements as documented in docs/dev/debt/relinker.md.[begin, end)is strictly enclosed within a single executable segment rather than merely checking endpoints, rejecting FDE ranges that cross segment gaps, while safely dropping empty FDEs (zero length) from removed functions.segment.FileSizeconsistently inEhFrameReader.test_tls_function_coverage.pyexpected message for theunwindmetadata variant to match the reader's check.unwind_record_bounds_testscovering boundary cases for relative displacements (value0xFFF0wrapping modulo 2^64 forDW_EH_PE_uleb128andDW_EH_PE_udata8), preserving upstream test additions, disjoint segment gaps, positivezSandzRSaugmentations, extra augmentation skipping, return address register column 16 (psABI x86-64 RA), unterminated augmentation strings, text-segment bounds, and valid landing pads.docs/dev/debt/relinker.md.Tested
upstream/main.unwind_record_bounds_tests.test_tls_function_coverage.py.python tools/check_conventions.py --base upstream/main --head HEADpassed with 0 findings.git diff --check upstream/main...HEADclean (exit 0).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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T14:12:16Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The focused unwind tests pass, but the new executable-segment check accepts an FDE whose range crosses an unmapped gap between executable segments.
What I ran
Reviewed head
362aa93e6530d63ef16cbadae63adb96f25e6bebagainstmainatbb04a4f1ea0175e9e4f149f0359a764d62ff3296. The merge preview is clean (tree2959c1942bf13024dee34b3fcbea4b277df981f5). Environment: Linux 6.1.0-54-amd64, GCC 12.2.0.Results
unwind_record_boundsfocused executableUnedited output
Negative control
[0x2000, 0x3010)with executable segments[0x2000, 0x2010)and[0x3000, 0x3010).[0x2010, 0x3000). This probe was not added to the PR test suite.Findings
Blocking
inTextSegmentchecks individual addresses, andreadFdechecks only the first and final byte of the FDE range. Thus two endpoints in separate executable segments let the FDE cover a non-executable or unmapped gap. The focused fixture above reproduces this. Validate that the entire half-open range is covered by executable mapped memory (or otherwise reject ranges crossing segment gaps), and add a regression test for this case.Non-blocking
Sources
EhFrameReader.cpp, executable-segment membership and FDE range checksNot verified
A full CMake build/CTest run, other operating systems, sanitizer builds, and PS5 behavior were not run or confirmed here.
To get this to a good state
Check full-range executable coverage and add a disjoint-segment gap regression case. I will rerun the same focused compile, conventions, and diff-check commands on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-29T16:27:43Z.
Review: CHANGES_REQUESTED
Thanks for the PR. The
relinker (ubuntu-latest),relinker (windows-latest)andrelinker-asanjobs fail, and I agree with the points already raised by @oneandonlydean, @MarcZX10 and @rooklz. To fix:tls_function_coverage_metadatafails (unwind-outside.elf,test_tls_function_coverage.py:580). The new FDE check inReadExceptionFunctionsfires beforeCode analysis: function exceeds executable segment(CodeInstructionCollector.cpp:217). Keep one source of truth for this case and update the test expectation for theunwindvariant only if the reader keeps the check.zS/zRSCIEs are rejected:EhFrameReader.cpp:208requires remaining augmentation bytes before every character, butSconsumes none. Move the bounds checks into the fields that read bytes and add positivezSandzRStests (a real Linuxlibc.so.6CIE useszRS).position != augmentationEnd(:258) rejects extra augmentation bytes that LSB lets readers skip. Skip toaugmentationEndinstead, unless real data says otherwise.:244): onlybeginandend - 1are checked, so[0x2000,0x3010)across executable segments[0x2000,0x2010)and[0x3000,0x3010)passes. Validate the whole interval against one containing segment, add that regression test, and say what you want for a leftover FDE of a removed function (begin 0 or outside text), which was accepted before.inTextSegmentusesmax(MemorySize, FileSize); the collector usesFileSize.main(EhFrameReader.cpp:163) and no CFA/register-rule validation was added, only the return-address column. Also compute the case count in the test output instead of printing a literal25, and state which rule you intend for full-width ULEB128 (rejected) versusudata8(wraps), with a boundary test.Welcome to push an updated head with these addressed.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-30T13:03:33Z.
Review: CHANGES_REQUESTED
Thanks for the update. The
zS/zRS, extra-augmentation, whole-interval FDE andFileSizepoints look addressed. Still open from the previous review:EhFrameReader.cpp:209rejects every other column. Give the source (psABI x86-64 register 16 is RA) in the description, or label it an assumption for console binaries.udata8: the description says ULEB128 relative overflow is covered by a test, but I find no boundary test for it inUnwindRecordBoundsTests.cpp. Add one (value just under and over the limit) so the rule "uleb128 throws, udata8 wraps" is pinned.CI on this head was still running when I reviewed; it needs to be green before merge.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:17:56Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the source reviewed; the claimed runtime checks were not independently run.
What I ran
Reviewed head
d3ef816a61c8100b3b8e4cd499d3e6872de8b330. No commands or tests were run; repository access was read-only throughrepo_read.py.Results
Findings
Blocking
None identified in the reviewed source.
Non-blocking
None.
Not verified
The complete text of the four changed files listed in the manifest was read.
files.jsonwas unavailable; the prepared file listing shows all four changed files included. The author-reported test runs, platform builds, converter runs, and convention checks were not independently run. The rest of the repository and excluded files were not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T18:40:44Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
1372b5ece42487f324e2948d8ce5cb39e15e018b, basemain.encoded()function and the start ofCodeInstructionCollector.cppthrough the reader:Results
check_conventions.py,git diff --checkRaw reader output
Findings
Blocking
None verified.
Non-blocking
DW_EH_PE_uleb128displacements so that 0xFFF0 "throws overflow". The code does not do that.encoded()checks the overflow only for udata2, udata4 and the function-based absptr/udata8 cases (EhFrameReader.cpp:170, unchanged by this PR). uleb128 wraps silently. The test atUnwindRecordBoundsTests.cpp:102asserts the wrap (no throw), anddocs/dev/debt/relinker.md:350documents it as wrapping. The code, test and debt note agree with each other, so the wrong part is the description. Fix the description wording before merge.EhFrameReaderandCodeInstructionCollector. This PR does not changeCodeInstructionCollector.cpp, which already usesFileSizeat head. The sentence is misleading but harmless.inTextSegment()returns true when the binary has no executable PT_LOAD segment (EhFrameReader.cpp:67). The strict FDE and landing-pad checks then pass silently for such a binary. Probably intended, but worth a comment in the debt note if so.Not verified
test_tls_function_coverage.pywere not run. The test expectations are read from the diff only.readCie()andreadLsda()were not read in full at head. Onlyencoded()(EhFrameReader.cpp:141-182) was read.files.jsonwas not read. No exclusions are listed in the manifest.EhFrameReader.cpp(diff, plusencoded()at head). Files read from the diff only:UnwindRecordBoundsTests.cpp,test_tls_function_coverage.py,docs/dev/debt/relinker.md.Sources
encoded()at headTo get this to a good state
Nothing is required. Correcting the uleb128 sentence in the description is optional, but recommended before an approval.
Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-25T06:56:07Z.
Review: CHANGES_REQUESTED
Reviewed at
1372b5ece4, applied onmain7a1c9bbccf, relinker-only Release build (GCC, Ubuntu 22.04).main:unwind_record_bounds_testsno longer compiles:mainhas since added tests to the samemain()with these names (for example #14573 and the CFI landing-pad coverage), so the merge is textually clean but does not build.-k 0, the 34tls_function_coverage_*tests pass with the PR'sEhFrameReader.cppand the updatedtest_tls_function_coverage.py. WithEhFrameReader.cppfrommain,tls_function_coverage_metadatafails (function exceeds executable segmentinstead of the new FDE diagnostic), so the script change depends on the fix.Not mergeable until it is rebased and
unwind_record_bounds_testsbuilds and passes.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:54:32Z.
Review: COMMENTED
The trial merge with
mainis clean. I reviewed the CFI decode bounds and per-record rule validation in source. Please retain positive fixtures for both a normal compiler-emitted.eh_frameand an FDE that restores previously saved state, with their expected unwind rules checked. They would guard against tightening a record boundary at the expense of supported output. Please move the direct relinker debt edit to a fragment. I did not run the relinker suite for this head.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.