fix(relinker): validate ELF identification before parsing #2262
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2262"
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 NumberGuan on 2026-10-09T13:45:32Z.
What
ElfReader::ReadHeaderchecks the magic but reads all remaining fields using the ELF64 layout and host byte order regardless ofEI_CLASS,EI_DATAandEI_VERSION. Linux conversion accepts a synthetic image declaring ELF32, big-endian encoding or an invalid identification version, and writes an executable and registry.Require ELF64, little-endian encoding and identification version 1 before reading the remaining header fields. These identification bytes define how the file is interpreted in the ELF gABI. The check also runs before
--to-intelprocessing. Windows already rejects these inputs later inWindowsLoadImage; the shared check now rejects them before registry output.Extend the registered
elf_headerregression with 36 unsupported-identification cases and eight valid controls. It covers Linux and Windows output, with and without--to-intel, using the existing executable fixture. Invalid, unsupported and reserved values for each identification byte must exit 2 with the diagnostic and write neither executable nor registry; input bytes must stay unchanged. ELF64 little-endian inputs with System V and FreeBSD OSABI values still convert to the requested output format.Tested
Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, Ninja Release, Python 3.12.14. Based on upstream
d70b8998; contributiona213a26b.All 40 registered test groups passed in 76.20 seconds. Registration, conventions and whitespace checks passed. The existing
tls_function_coveragetest took 70.62 seconds; no repository timeout was changed.With only the regression added to upstream
d70b8998, the registered test fails:ident-4-0returns 0 and writes an executable and registry. The two-line fix passes the focused test in 2.78 seconds, including the existing short-file and magic diagnostics.Hosted relinker CI passed on Windows, Linux and macOS for
a213a26b. Hosted conventions also passed. The full Linux and Windows build jobs were skipped by the PR workflow. System-library builds and game/PS5 tests were not run locally.Checklist
main; no other open PR implements the same functionsImported from boykopovar/AnyPS5. Originally posted by MGXAe on 2026-10-09T14:04:22Z.
Independently confirmed on native Windows 11 (MinGW-w64 GCC 15.2.0 WinLibs r7): this PR's
test_elf_header.pyfails againstmain's relinker (ident-4-0converts with exit 0) and passes with this change.One thing to flag: #1087 (open since Oct 7) adds the same class, data-encoding and version checks in the same place in
ElfReader::ReadHeader(plus machine, ELF version and header-size checks), so the two will most likely conflict. The checklist line "no other open PR implements the same functions" may need updating.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-09T14:47:08Z.
Review: COMMENTED
Verified locally on Linux — this one needs no GPU.
d70b8998(upstream/main) + heada213a26b, merged clean.elf_headerPassed (0.05 s);linux_eh_frame_headerandlinux_load_alignmentpass too.ElfReader.cppreverted tomain, the PR's test kept):elf_headerfails, and the failing case isident-4-0—AssertionError: (0, 'ident-4-0', ...), i.e. onmainthe relinker returns0forEI_CLASS = 0, which is precisely what the new test rejects./bin/truewithe_ident[4]patched to1, so a valid ELF64 that claims ELF32:main:rc=0, wrote a 63,551-byte output and a registry — the "accepts a synthetic image declaring ELF32 and writes an executable and registry" case from the description, reproduced.rc=2, no output, no registry,FAIL: Expected little-endian ELF64 version 1.eboot.binstill converts,rc=0, output 43,239,463 bytes — identical in size to the same conversion onmain.Pre-checks done before measuring:
ReadHeaderalready validatessize >= 0x40, the SELF magic and the ELF magic, so the new guard is not shadowed (the #1521 failure mode), andReadHeaderis genuinely reachable (ReadProgramHeaders,StrictNidFilter).One design detail worth keeping:
EI_OSABIis left unchecked, and the test pins that by requiring a FreeBSD-flagged image (e_ident[7] = 9) to still convert. That matters here — PS5 modules carry unusual identification (e_type0xfe18on a title's ownlibc.prx), so a stricter guard would have cost real inputs.This is a relinker fix, so it does not need a named title; it is provable against the ELF gABI by itself.
What I could not verify: a Windows host, and ELF producers beyond
/bin/true.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:08:41Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/relinker/tests/test_elf_header.pyL5, L20-22