[Memory/input reliability] Validate ELF symbol ranges and preserve allocator regressions #1666
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Sanjaysrinivas on 2026-10-08T16:03:05Z.
Split from #1659. Category: memory and input reliability. This tracks conversion correctness and stable allocation behavior during emulator use.
Problem and expected outcome
The relinker must reject inconsistent ELF metadata before reading outside the input image. Failed allocation requests must leave existing allocations usable. These are prerequisites for diagnosing conversion failures and crashes reliably: an invalid read or damaged allocation can make later symptoms unrelated to their original cause.
The remaining concrete source-level concern is the symbol-entry calculation in
RelinkerPipeline::Relink. The original allocator-resize and RELA-entry findings have already been fixed upstream and should remain regression controls.Evidence and affected code
Baseline checked: upstream
4b005b229e24be9ec3f185def9e59cbc03aa9e4a.RelinkerPipeline.cpp, symbol lookup calculatessymOff = dynSymTabOffset + symIdx * symEntSize, checkssymOff + 4 > raw.size(), and then copies four bytes fromraw.data() + symOff.DT_OS_SYMTABis accepted as a file offset throughreadAsOffset. The symbol-table base is not first checked against the input size at this lookup. The base-plus-index addition and the subsequent+ 4check can wrap, so the condition does not establish that the bytes are in the input image.mspaceresize requests.tests/Mspace.cppalready checks near-maximum sizes, allocation contents, usable size, and allocator statistics. Extend or retain these tests instead of recreating them.Evidence level: the remaining symbol-offset concern was verified by source inspection at this baseline. This issue does not claim a new runtime reproduction or a game-specific crash from that concern. The earlier allocator/RELA findings are resolved work, not new open defects.
Reproduction and diagnosis procedure
Use the synthetic ELF builder in
test_optional_plt.pyas the starting point; no game files are needed.RELATIVE, which skips symbol lookup.relinker --skip-sce-module --windows <input.elf> <output.exe>. Also cover the Linux output path where the fixture supports it.Expected behavior is a controlled conversion error identifying the invalid table/entry. The test must not pass merely because any nonzero process exit occurred: a crash is a failure, not valid rejection.
Implementation work
Validation matrix
Run applicable fixture tests on Windows and Linux and in Release. The testing/release category owns the shared instrumented CI lane; this category owns the input cases and behavioral assertions.
Acceptance criteria
Scope and dependencies
Keep the relinker's C++20 standard-library constraint. Start with the concrete symbol-entry check and focused tests; additional infrastructure is unnecessary for the first fix. This issue can progress before the shared CI improvements. No claim about complete title compatibility follows from parser or allocator tests alone.
Related category issues
Imported from boykopovar/AnyPS5. Originally posted by StarMrGamer on 2026-10-09T11:52:09Z.
Checked the open pull requests in this cluster against
main(d70b8998). They are complementary, not duplicative: each bounds a different read, and inRelinkerPipeline.cppthey touch different hunks (around lines 59-90, 165 and 218) or different files, so they can land in any order with at most a trivial rebase.Each branch was built in its own worktree, relinker-only (
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, GCC 16.2.1, Linux x86-64), andctestis clean in all five:RelinkerPipeline.cpp:218DT_RELAtable rangeRelinkerPipeline.cpp:165PT_DYNAMICand duplicate DT tagRelinkerPipeline.cpp:59-90EntryPointCollector.cppCallSiteResolver.cppThe three 39-test branches are based on an older
mainthan the 44-test ones (five tests have been added since);#1446isCONFLICTINGagainst currentmainbut builds fine as a branch.Against this issue's acceptance criteria, #1272 is the one that covers the symbol-entry row. It replaces
if (symOff + 4 > raw.size())withif (symOff < dynSymTabOffset || symOff > raw.size() || raw.size() - symOff < 4), which closes both the wrapping sum and the range check.One item in the implementation checklist is still implicit: "State whether the parser requires the complete 24-byte ELF64 symbol entry or only the fields it intentionally reads." #1272 requires only the 4 bytes it dereferences, so a truncated entry that still carries
st_nameis accepted and the name is then resolved through the separately bounded string table. That is memory-safe, but it is a deliberate choice and should be stated, because the matrix row for a valid entry at the boundary expects acceptance "according to the documented entry-size requirement", and nothing documents that requirement yet.For the adjacent-read review item, these five PRs are the concrete findings that came out of it; I did not find an unchecked read pattern along this pipeline that none of them covers.
Imported from boykopovar/AnyPS5. Originally posted by StarMrGamer on 2026-10-09T16:57:59Z.
Update to the table above: #1446 has been rebased (
5de529ff→c917df8f, the same two commits) and now reportsMERGEABLEinstead ofCONFLICTING, so the last paragraph of that comment no longer applies.Re-verified the new head here: configure and build clean,
ctest44/44 (it picks up the five tests added tomainsince it was branched),check_conventions.pyclean.All five pull requests are now
MERGEABLE, and the other four heads are unchanged from what I built: #127284d851bf, #19388ee83315, #2196fcba0b0d, #2091d5d6e577.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:07:53Z.
Fixed by #1272: the symbol-entry read in
RelinkerPipeline.cppnow rejects a wrapped or out-of-range offset ("Symbol table entry out of bounds"), and #1446 bounds theDT_RELArange. The allocator items were already fixed, so closing.