fix(relinker): validate the ELF object version and header size #4441
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4441"
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 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 main3d8ffeb27, 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_headerwith 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 intendedNo PT_DYNAMICdiagnostic.Tested
Windows x64, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release, Python 3.12,
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON, based on main9c99f4344.3d8ffeb27: version 0 and header size 0 both exit 0 and create output.header-0-0-20-0(version 0 accepted) and passes after the latest rebase.tools/check_conventions.py --base origin/mainandgit 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 onto9c99f4344.Checklist
main; the existing machine check from merged #3809 is retainedImported 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'sMODESrefactor 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 toheader-only-sections).No PT_DYNAMICerror. 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):tools/check_conventions.py --base origin/mainpassesTo pick it up:
Head is
9121fd808.