fix(relinker): validate ELF section tables #1956

Closed
arcwiser wants to merge 1 commit from upstream-pr/1956 into main
arcwiser commented 2026-10-09 02:09:59 +00:00 (Migrated from github.com)

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_reader test 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_tests
  • ctest --test-dir build-relinker --output-on-failure -R ^elf_reader$: passed
  • python tools/check_test_registration.py build-relinker: 8 executables, all registered
  • Relinker suite excluding the five Windows-build-26200 loader failures reported in #1955: 32/32 passed
  • python tools/check_conventions.py --base origin/main: passed
  • git diff --check: passed
  • python tools/pr_overlap.py --branch HEAD --repo boykopovar/AnyPS5: no overlap

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR; follow-ups go in a new PR
  • No code comments added
  • Unimplemented paths still throw
  • No investigation files or images added
  • No third-party code added
  • Generic behaviour, not title-specific
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4795060128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1956). Originally posted by [arcwiser](https://github.com/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_reader` test 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_tests` - `ctest --test-dir build-relinker --output-on-failure -R ^elf_reader$`: passed - `python tools/check_test_registration.py build-relinker`: 8 executables, all registered - Relinker suite excluding the five Windows-build-26200 loader failures reported in #1955: 32/32 passed - `python tools/check_conventions.py --base origin/main`: passed - `git diff --check`: passed - `python tools/pr_overlap.py --branch HEAD --repo boykopovar/AnyPS5`: no overlap ### Checklist - [x] Based on current `main`; no other open PR implements the same change - [x] One topic per PR; follow-ups go in a new PR - [x] No code comments added - [x] Unimplemented paths still throw - [x] No investigation files or images added - [x] No third-party code added - [x] Generic behaviour, not title-specific - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-09 02:13:36 +00:00 (Migrated from github.com)

Imported 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5464951849 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1956#pullrequestreview-5464951849). Originally posted by [MarcZX10](https://github.com/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.
MarcZX10 commented 2026-10-09 02:13:55 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072856250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1956#issuecomment-6072856250). Originally posted by [MarcZX10](https://github.com/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.
oneandonlydean commented 2026-10-09 08:56:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:56:48Z.


Closing: nothing on main calls ReadSectionHeaders (or _resolveShdrName through it), so these checks never run during a relink. They're worth bringing back with the first change that reads the section table.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077734819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1956#issuecomment-6077734819). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:56:48Z. --- Closing: nothing on main calls `ReadSectionHeaders` (or `_resolveShdrName` through it), so these checks never run during a relink. They're worth bringing back with the first change that reads the section table.
krishalivaibhav commented 2026-10-09 08:57:21 +00:00 (Migrated from github.com)

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 1dd90890 combined with main 6cc0503d on 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077743034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1956#issuecomment-6077743034). Originally posted by [krishalivaibhav](https://github.com/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 `1dd90890` combined with main `6cc0503d` on 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1956
No description provided.