fix(relinker): bound the symbol and relocation table reads #1272
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1272"
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 Dextroid17 on 2026-10-07T20:57:22Z.
What
Two reads of the dynamic tables check bounds with arithmetic that can wrap, or not at all.
The symbol table,
RelinkerPipeline.cpp:210.dynSymTabOffsetcomes straight fromDT_OS_SYMTABand is never bounded, and the check adds four to the offset:extractRelative,RelinkerPipeline.cpp:293.pos = relaOff + off, thenmemcpy(raw.data() + pos, 8)with no bounds check at all, while its siblingextractRelaat least has one.Both now compare against
raw.size()without adding to the offset first, and reject an offset below the table start, which is what a wrapped sum produces. The symbol table has no size tag to bound it with, so that check stays per entry, where it was.The symbol table case was first reported by @muhzain05 in #917's thread; this makes it a bound on the read rather than another case of the same arithmetic.
Tested
core/relinker/relinker/tests/DynamicTableBoundsTests.cppcrafts an ELF whoseDT_OS_SYMTABis0xFFFFFFFFFFFFFFFE, and requires the relinker to report the entry as out of bounds. It is registered asdynamic_table_boundsand drives the real CLI throughRelinkerProcess.hpp.Failing on
main, proven by reverting only the implementation and rebuilding:The wrapped offset lands on a byte that is not the entry, so the relinker reports an unrelated problem in another function. With the change it reports
Symbol table entry out of bounds (offset ...).Full suite on Linux (CachyOS, GCC 16.2.1): 405/405 pass, including the new test.
What the test does not cover: the
extractRelativecheck has no differential case.extractRelareads the same entries first and its own arithmetic wraps identically, so onmainthe garbage entry usually trips a later check beforeextractRelativeis reached; the guard matters for the case where that garbage entry happens to look relative and is skipped. Saying so rather than implying a second proven case.This does not touch
extractRela, which #917 repairs — that path already has an open PR.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T03:10:37Z.
@oneandonlydean ready for eyes — bounds the symbol and relocation table reads in the relinker pipeline, with a test that fails on an unbounded read. Four checks green.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T06:37:20Z.
#917 is on main and now bounds
extractRelativethroughrelaEntryPos, so that hunk is no longer needed and the PR conflicts inRelinkerPipeline.cppandcore/relinker/CMakeLists.txt. Please rebase with just the symbol table check and its test.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T10:37:40Z.
Agreed — #917 now bounds
extractRelativethroughrelaEntryPosonmain, so that hunk is stale. I'll rebase down to just the symbol-table bounds check and its test and drop theextractRelativehunk, then re-run the suite on the rebased head before asking for another look.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T10:46:30Z.
Rebased on current
mainas asked — the relocation hunk is gone, sincerelaEntryPosfrom #917 now boundsextractRelative. What is left is the symbol-table half:DT_OS_SYMTABis returned raw byreadAsOffset, so a bogus value reaches this check — andsymOff + 4wraps forsymOff == 0xfffffffffffffffe, so thememcpyreads the name pointer frombase - 2inside the file and the failure surfaces somewhere else entirely.Negative control — test kept, only the implementation reverted to
main:So on
mainthe bogus offset is not rejected at the read, and what a title would see is a message that names no cause. With the bound in place the run stops atSymbol table entry out of bounds.-DANYPS5_ENABLE_SPIRV_TOOLS=ON): full suite 441/441 passed (29 s).python3 tools/check_conventions.py --base upstream/mainpasses.symIdx = 1on purpose: with no relocation referencing a symbol the symbol table is never read, so there is nothing to bound. That one-entry table isDT_RELASZ = 24.dynamic_table_boundsis registered next to #917'srela_bounds, so both halves of the dynamic table are covered by a test that fails on the code without the guard.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T14:49:18Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/CMakeLists.txtL310Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T16:08:58Z.
Rebased onto current
main(4b005b22) and the four checks are green again as of today:Nothing further is planned on this branch — it is ready for a review pass whenever you have a moment. Command output for both runs is in my comment from earlier:
441/441onmainwith the old test, then the negative control failing on the non-NUL-terminated string, then green with the bound in place.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-08T17:40:08Z.
Status, since it affects how this one lands:
@MarcZX100closed #1682 this evening as a duplicate of this PR — "its current head already contains the same subtraction-based symbol-entry bounds check and has all four upstream checks passing" — so this is the canonical implementation of the bound.main(2b297842): both merges apply in order without conflict, the full relinker suite is 38/38 on Linux, and with this bound reverted tomain'ssymOff + 4 > raw.size()both new tests fail — so they gate the fix rather than passing beside it.MERGEABLE / CLEAN, all four checksSUCCESS, rebased onto currentmain.Merge this first, then #1690 on top.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:42:30Z.
Checked on a Linux build merged onto current
main: full ctest 551/551 passes. Reverting only the check and rebuildingrelinkermakesdynamic_table_boundsfail (Dynamic string is not NUL-terminated within DT_STRSZ); with the check it reportsSymbol table entry out of bounds. The test is registered explicitly in ctest. Merging.