fix(relinker): validate ELF section tables #1956
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1956"
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 arcwiser on 2026-10-09T02:09:59Z.
What
Reject malformed ELF64 section tables before parsing them. Validate the 64-byte section-header stride, the complete table range, the section-name string-table index and range, each name offset, and NUL termination inside the declared string table.
Add a focused
elf_readertest covering a valid table plus zero, undersized and oversized strides, an invalid string-table index, an invalid name offset, an unterminated name, and an out-of-file string table.Tested
Windows 10.0.26200, documented WinLibs GCC 15.2.0 and Ninja 1.13.2:
cmake --build build-relinker --target elf_reader_testsctest --test-dir build-relinker --output-on-failure -R ^elf_reader$: passedpython tools/check_test_registration.py build-relinker: 8 executables, all registeredpython tools/check_conventions.py --base origin/main: passedgit diff --check: passedpython tools/pr_overlap.py --branch HEAD --repo boykopovar/AnyPS5: no overlapChecklist
main; no other open PR implements the same changeImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T02:13:36Z.
Review: APPROVED
Reviewed the full diff against current main. The section-header table range is checked before iteration, the entry stride and string-table index are validated, and section names are bounded by the declared string-table range and NUL terminator. The valid SHN_UNDEF/no-name-table path remains accepted. I built and ran Test project /marc/AnyPS5 on Linux; both passed. The author also reports the targeted Windows 26200 regression reproduction and relinker suite. GitHub currently reports no checks for this head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T02:13:55Z.
Correction to my review text: shell quoting removed the target and test name from the posted body. I did build the elf_reader_tests target and run CTest test elf_reader locally on Linux; both passed. GitHub reports no checks for this head.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:56:48Z.
Closing: nothing on main calls
ReadSectionHeaders(or_resolveShdrNamethrough it), so these checks never run during a relink. They're worth bringing back with the first change that reads the section table.Imported from boykopovar/AnyPS5. Originally posted by krishalivaibhav on 2026-10-09T08:57:21Z.
Adding Apple Silicon validation for reference if section-table reading is introduced later. I saw the closure explanation that main does not currently call ReadSectionHeaders; these results validate the reader directly, not a failure in the current relink path.
Tested PR head
1dd90890combined with main6cc0503don Apple M2 / 16 GB, macOS 27.2, AppleClang 17, CMake 4.4.4 and Ninja 1.13.2. The merge was conflict-free; the relinker-only Release build succeeded and 35/35 registered CTest tests passed with a 30-second timeout (4.76 s total).Compiling the new ELF-reader test against baseline main reproduced invalid-section-table acceptance; the patched implementation passes. Four additional local probes also produced the expected section-table bounds diagnostic: a table starting at EOF, at EOF-1, at UINT64_MAX, and a file truncated one byte before the end of the declared table. These would be useful coverage if this change is brought back alongside a real caller.
No game execution or full runtime validation was performed. AI-assisted validation using Codex.
Pull request closed