fix(relinker): validate the ELF object version and header size #4441

Merged
superhe11 merged 1 commit from upstream-pr/4441 into main 2026-10-13 00:34:03 +00:00
superhe11 commented 2026-10-12 11:41:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by superhe11 on 2026-10-12T11:41:30Z.


What

The executable relinker accepts an unsupported ELF object version (e_version) or header size (e_ehsize) and generates output instead of rejecting the input. On main 3d8ffeb27, changing a valid fixture to object version 0 or header size 0 still exits 0 and creates an output file.

Validate object version 1 and the supported 64-byte ELF header in ElfReader::ReadHeader, before program-header parsing or Intel/Rosetta instruction conversion. Each rejection names the invalid field and its offset. The field definitions are in the ELF gABI.

Extend elf_header with 126 rejection cases across Linux ELF, Windows PE, macOS Mach-O, Intel/Rosetta conversion, and unused-filter levels 0/1/2. Check input preservation and absence of an output executable or registry. Extend the existing valid System V/FreeBSD identification cases to macOS and Rosetta output, and give the strict-filter fixture its previously missing object version and header size.

Rebased on main 9c99f4344, which includes the machine check from #3809. Retain its per-case error-message harness and both header-only cases. Set version 1 and header size 64 in the no-program-headers fixture so it still reaches its intended No PT_DYNAMIC diagnostic.

Tested

Windows x64, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release, Python 3.12, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON, based on main 9c99f4344.

  • Baseline reproduction on main 3d8ffeb27: version 0 and header size 0 both exit 0 and create output.
  • The extended regression fails against that baseline at header-0-0-20-0 (version 0 accepted) and passes after the latest rebase.
  • Latest local relinker-only build and CTest: 133/133 passed (27.25 seconds for the parallel suite).
  • tools/check_conventions.py --base origin/main and git diff --check: passed.

Linux/macOS output generation was tested on Windows. No native Linux/macOS execution or commercial game verification was performed locally. Separately, @blawesom reported a Linux full-suite result of 959/959 on the provided rebase handoff 9121fd808 (CachyOS, GCC 16.2.1, RX 9070 XT/RADV); that full Linux suite was not rerun after rebasing onto 9c99f4344.

Checklist

  • Based on current main; the existing machine check from merged #3809 is retained
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt (no new comments)
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (no new dependencies)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4828877652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4441). Originally posted by [superhe11](https://github.com/superhe11) on 2026-10-12T11:41:30Z. --- ### What The executable relinker accepts an unsupported ELF object version (`e_version`) or header size (`e_ehsize`) and generates output instead of rejecting the input. On main `3d8ffeb27`, changing a valid fixture to object version 0 or header size 0 still exits 0 and creates an output file. Validate object version 1 and the supported 64-byte ELF header in `ElfReader::ReadHeader`, before program-header parsing or Intel/Rosetta instruction conversion. Each rejection names the invalid field and its offset. The field definitions are in the [ELF gABI](https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html). Extend `elf_header` with 126 rejection cases across Linux ELF, Windows PE, macOS Mach-O, Intel/Rosetta conversion, and unused-filter levels 0/1/2. Check input preservation and absence of an output executable or registry. Extend the existing valid System V/FreeBSD identification cases to macOS and Rosetta output, and give the strict-filter fixture its previously missing object version and header size. Rebased on main `9c99f4344`, which includes the machine check from #3809. Retain its per-case error-message harness and both header-only cases. Set version 1 and header size 64 in the no-program-headers fixture so it still reaches its intended `No PT_DYNAMIC` diagnostic. ### Tested Windows x64, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release, Python 3.12, `ANYPS5_RELINKER_ONLY=ON`, `BUILD_TESTING=ON`, based on main `9c99f4344`. - Baseline reproduction on main `3d8ffeb27`: version 0 and header size 0 both exit 0 and create output. - The extended regression fails against that baseline at `header-0-0-20-0` (version 0 accepted) and passes after the latest rebase. - Latest local relinker-only build and CTest: 133/133 passed (27.25 seconds for the parallel suite). - `tools/check_conventions.py --base origin/main` and `git diff --check`: passed. Linux/macOS output generation was tested on Windows. No native Linux/macOS execution or commercial game verification was performed locally. Separately, @blawesom reported a Linux full-suite result of 959/959 on the provided rebase handoff `9121fd808` (CachyOS, GCC 16.2.1, RX 9070 XT/RADV); that full Linux suite was not rerun after rebasing onto `9c99f4344`. ### Checklist - [x] Based on current `main`; the existing machine check from merged #3809 is retained - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt (no new comments) - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source (no new dependencies) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
blawesom commented 2026-10-12 17:34:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T17:34:48Z.


Rebase handoff — rebased onto current main, authorship unchanged.

Three conflicts, all resolved with both sides' intent preserved:

  • ElfReader.cpp: main's x86-64 machine check and this PR's version + header-size checks are kept together (three validations in sequence).
  • test_elf_header.py (two regions): main's per-case error-message harness and this PR's MODES refactor are combined — message strings win over the boolean form since main's machine cases need their own messages. Main's new "header-only" case and this PR's fixture-based one both survive (the PR's renamed to header-only-sections).
  • One real interaction found: main's "header-only" fixture predates this PR's validation, so its version and header-size fields are zero and this PR's checks now reject it before the intended No PT_DYNAMIC error. The handoff fixes the fixture (version=1 at 0x14, header size=64 at 0x34) so the case tests what it meant to.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 959/959 passed (including all elf tests)

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/4441
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 9121fd808.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6129358809 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4441#issuecomment-6129358809). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T17:34:48Z. --- **Rebase handoff** — rebased onto current `main`, authorship unchanged. Three conflicts, all resolved with both sides' intent preserved: - `ElfReader.cpp`: main's x86-64 machine check and this PR's version + header-size checks are kept together (three validations in sequence). - `test_elf_header.py` (two regions): main's per-case error-message harness and this PR's `MODES` refactor are combined — message strings win over the boolean form since main's machine cases need their own messages. Main's new "header-only" case and this PR's fixture-based one both survive (the PR's renamed to `header-only-sections`). - **One real interaction found:** main's "header-only" fixture predates this PR's validation, so its version and header-size fields are zero and this PR's checks now reject it before the intended `No PT_DYNAMIC` error. The handoff fixes the fixture (version=1 at 0x14, header size=64 at 0x34) so the case tests what it meant to. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 959/959 passed** (including all elf tests) **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/4441 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `9121fd808`.
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!4441
No description provided.