fix(relinker): preserve GNU stack and RELRO headers on Linux #6406
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6406"
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 MarcZX10 on 2026-10-15T14:12:43Z.
What
PT_GNU_STACKandPT_GNU_RELROwhen filtering Linux program headers.PT_GNU_RELROwhen lazy binding is enabled, because PS5 lazy PLT targets can fall inside that range and must remain writable for first-call resolution.Tested
linux_gnu_segments.python3 tools/check_conventions.py --base upstream/mainpassed.git diff --checkpassed.R_X86_64_JUMP_SLOTtargets were insidePT_GNU_RELROwith noBIND_NOW. This was a layout/code analysis, not a runtime reproduction.c56cafae2: the fullyPT_LOAD-coveredPT_GNU_RELROis retained, ld.so applies read-only protection, and the title runs until its pre-existing sRGB compute-sample failure. This covers the retained RELRO path only; the reported Astro Bot/Dreaming Sarah startup reruns and aPT_GNU_STACKtitle case remain outstanding.Checklist
main; no other open PR implements the same functions.mdfiles or images addedImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T14:33:55Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/elfpatcher/src/general/SegmentFilter.cppcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/CMakeLists.txtcore/relinker/relinker/src/pipeline/Conversion.cppImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T12:33:54Z.
Tested 90f5c3710 as-is (merge base
0dab493f5; it still merges cleanly intomaineb901bcf4) on Linux (CachyOS, kernel 7.2.9), relinker-only Release build withBUILD_TESTING=ON, as in the CI relinker job:ctest -R '^linux_gnu_segments$': passed, 3 of 3. The full relinker suite passed, 182/182.SegmentFilter.cppline removed and the relinker rebuilt: failed, 3 of 3,PT_GNU_STACK was dropped. With the line restored and rebuilt, it passes again.I also relinked a real eboot with both builds: Ghost of Yōtei (PPSA26344 v01.008). Its eboot has a
PT_GNU_RELROand noPT_GNU_STACK.PT_GNU_RELRO, with the same address and memory size as the RWPT_LOADit covers (0x1b34000, 0x1dc000). Without the line it is dropped.PT_GNU_STACK.#6447 changes the same line (L15, flagged by the overlap bot), without a relinker test or a reference to #6394, so the two will conflict. This one was opened first and carries the regression test. #6447 also changes
RebaseProgramHeadersto usetableOffinstead ofphOffinLinuxElfPatcher.cpp, which is the change in #6403; I did not test that path.Not run: Windows, macOS, a hardware GPU, a boot past 150 s.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T15:59:24Z.
Thanks for the full relinker suite, 3/3 focused regression and reverted-line control. The real Ghost of Yōtei eboot comparison is useful evidence that GNU RELRO is retained; I have noted the 150-second boot window and that the PT_GNU_STACK half is not exercised by that eboot. I will review the #6447 overlap and the shared #6403 program-header path separately before any consolidation.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T10:38:38Z.
Thanks. Keeping
PT_GNU_STACKandPT_GNU_RELROlooks right for the default (BIND_NOW) output. One question and a rebase:Lazy binding: with
--lazy-binding, keepingPT_GNU_RELROcan leave the original.got.pltinside the read-only range, so the first lazy call would fault when the loader writes the resolved address. We found this reading the code and haven't reproduced it. Could you check the--lazy-bindingoutput: either keep.got.pltoutside RELRO in that mode, or drop RELRO there?The branch is about 600 commits behind main, so please rebase onto current main before we run CI.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T12:30:05Z.
I rebased the PR onto current
main(c9e6c45de) as497cf2569; the single commit remains authored and committed by MarcZX100. The relinker-only Linux build,linux_gnu_segments(1/1), conventions, andgit diff --checkpass.I checked the lazy-binding concern against a GNU-linked Linux PIE built with
-z lazy -z relro: it has noBIND_NOW; itsPT_GNU_RELROcovers 0x3dd0–0x4000 while.got.pltspans 0x3fe8–0x4008, leaving the mutable PLT slot outside RELRO. This host binary is rejected by AnyPS5’s instruction decoder before relinking, so I could not validate a converted output. I also could not find a PS5 ELF fixture here to establish whether itsPT_GNU_RELROcovers lazy PLT relocation targets. The current evidence does not show a failure, but it does not settle the PS5 layout case; a representative input with its dynamic relocations would let us check whether the writable lazy slots fall inside the preserved range.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T12:51:12Z.
Thanks for the rebase and the host check. We checked the PS5 side on a real eboot (Ghost of Yōtei), and PS5 links don't lay it out the way GNU ld does:
PT_GNU_RELROcovers 0x1b34000–0x1d10000, which is the whole RWLOAD.R_X86_64_JUMP_SLOTtargets (0x1d0d440–0x1d0ea08,DT_PLTGOT0x1d0d428) are inside that range.BIND_NOW.The Linux patcher copies the PLT relocations unchanged and leaves out
DF_BIND_NOWwhen--lazy-bindingis set. So with this change, ld.so would make every lazy slot read-only, and the first lazily bound call would fault. This comes from reading the layout and the code, not from a run.The default (BIND_NOW) output is fine as it is. Could you skip
PT_GNU_RELROwhen lazy binding is on (or drop it in that mode), and add a lazy-binding case to the test? After that we'll run full CI.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T13:32:35Z.
Rebased onto current upstream main (
40315fcf8) and addressed the lazy-binding review:PT_GNU_RELROis omitted only when lazy binding is enabled, while default/eager output continues preserving it. The regression checks lazy-mode omission and eager/default retention. Linux relinker-only Release build and full CTest suite pass (188/188); conventions andgit diff --checkpass. The PS5 layout concern is based on reviewer analysis of a real eboot's relocation targets, not a runtime reproduction.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T13:38:48Z.
Follow-up: GitHub CI has now passed the relinker-only build and test jobs on Linux (GCC), macOS (Clang), and Windows (GCC), along with conventions and eligibility. The broader application Linux/Windows jobs were skipped by the relinker-only path filter. My local Linux relinker-only CTest run also passed 188/188.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T19:46:53Z.
Thanks for the RELRO / lazy-binding follow-up. We ran this head (
55497ed3a) on two titles with the relinker's default options (eager binding, soPT_GNU_RELROis kept), rebased onto main52798f71d, and both produced executables fail to start:That's glibc's loader failing the
mprotectit does over thePT_GNU_RELROrange after relocation.ENOMEMfrommprotectusually means part of that range isn't mapped, so the RELRO segment the relinker keeps probably isn't fully covered by aPT_LOADsegment in the relinked output (or it extends past one). The host had plenty of memory, and the same relinker without this PR loads and runs both titles on the same main.Two independent relinks (10.7 MB and 266 MB executables) fail identically, so it isn't title-specific.
linux_gnu_segmentschecks that the header is present but doesn't load the output, which is why CI passed.Could you check where the preserved
PT_GNU_RELROlands relative to thePT_LOADsegments after relinking (readelf -lWon a relinked binary), and either clamp or drop it when it isn't fully inside a writablePT_LOAD? A test that actually executes a relinked binary in the default mode would catch this. Happy to rerun the titles on a new head.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-17T20:24:17Z.
Independent Linux loader reproduction of the new default-mode failure mechanism on exact head
55497ed3a4a90621074323fea8d9602a66f49f2b(Ubuntu 24.04 x86-64, glibc 2.39, GCC 13.3, Release relinker-only). Production source unchanged; all inputs generated from this branch's fixture.linux_gnu_segmentspasses. I then executed 15 relinked outputs: five RELRO geometries × default eager / fixed-base eager / lazy. The generated guest entry is anint3, so SIGTRAP proves the loader reached it.[0x4000,0x8000)RELRO: eager and fixed-base both reach entry;straceshows a successful 16 KiBmprotect(PROT_READ). Both RW and R-only LOAD controls work.[0x4000,0xc000)RELRO: eager and fixed-base both exit 127 with the exact reported glibc message. The RW LOAD ends at0x8000; the synthetic block occupies one page there, leaving a hole before the relocated header LOAD at0xc000.straceshows the 32 KiBmprotect(PROT_READ)returning ENOMEM.[0x1000,0x8000)also reproduces it, with the 28 KiB protection call returning ENOMEM.[0x4500,0x4600)reaches entry without any mprotect call. The current stock fixture's[0x500,0x600)similarly has no full host page to protect. An execution regression should include a full-page range; merely executing that existing small fixture would still miss the protection path.Minimal failing generated input, using the existing test helpers:
Relink with
--skip-sce-module relro-hole.input relro-hole.elf, chmod the output executable, then run it (orstrace -e mprotect ./relro-hole.elf). Changing only the RELRO memory size above from0x8000to0x4000gives the mapped positive control. Add--linux-fixed-base 0x400000to cover rebasing, or--lazy-bindingto cover omission.Limit: this intentionally supplies a RELRO range exceeding the input LOAD; it proves the unchecked-preservation failure and provides a loader-level regression, not why the real title's range becomes uncovered. No retail assets were used, no title boot is claimed, and I have not tested a clamp/drop production fix. The two failing title outputs'
readelf -lWremains necessary to establish their specific layout cause.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T20:47:12Z.
Thanks for the executable-level reproduction and the full-page positive/negative controls. I agree the fixture now demonstrates that preserving a PT_GNU_RELRO range which extends across an unmapped hole can make glibc fail its protection call, while lazy binding and changing only the header to PT_NULL isolate that mechanism. I am not treating that as proof of the two retail outputs’ layout cause. I’ll inspect their
readelf -lWoutput if those exact relinked artifacts are available; otherwise I’ll keep the production conclusion limited to the synthetic failure and ask for the artifact details before changing range handling. The useful regression addition is clear: execute a generated full-page RELRO case with both a fully mapped passing control and an overhanging failing control.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:39:58Z.
Here are the
readelf -lWprogram headers from the two relinked retail outputs our gate produced on55497ed3a(built on main). Both fail withcannot apply additional memory protection after relocation: Cannot allocate memory.Astro Bot (
eboot.linux, the relevant rows):The RW LOAD ends at 0x8e3c3e8, or 0x8e3d000 rounded up to a 4 KiB page. GNU_RELRO's MemSiz is 0x564000, which ends at 0x8e40000. So 0x8e3d000..0x8e40000 (3 pages) is covered by RELRO but by no LOAD.
Dreaming Sarah (
app.elf):Here the RW LOAD ends at 0x495380 (0x496000 rounded to a page), and RELRO ends at 0x498000: 2 uncovered pages.
In both outputs the RELRO MemSiz is the LOAD's size rounded up to the PS5's 16 KiB granule (0x4000), but the LOAD itself is mapped at 4 KiB host pages, so the tail lands in the gap before the next LOAD. That's the same shape as the overhanging control in the fixture. A clamp of
p_memszto the end of the RW LOAD it starts in (page-rounded at the host page size), or dropping RELRO when it isn't fully covered, would fit both outputs. Full headers for both files are available if you want them.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T21:43:57Z.
I updated the PR with a conservative check and executable coverage for the loader failure. In both default and fixed-base modes, a fully covered full-page RELRO range is retained and the output reaches the generated SIGTRAP entry; an overhanging range is omitted and also reaches the entry. The full Linux relinker-only CTest suite passes 188/188. I still do not have the two retail outputs, so this does not establish their exact program-header layout or claim those title failures are fixed. Could you rerun them on this head and share
readelf -lWoutput if either still fails?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T21:46:23Z.
Thanks, these headers confirm the same overhang shape as the new regression: both RELRO ranges extend beyond the final page of the writable PT_LOAD that begins at the same address. The updated filter page-rounds the PT_LOAD coverage to the host load alignment and omits a RELRO range if any page is uncovered, so these two layouts should take the omission path. Could you rerun both outputs on commit
c56cafae2and report whether they reach startup? If either still fails, the full header dump would help trace the remaining mapping.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T21:49:46Z.
CI has now completed successfully on the updated head
c56cafae2: eligibility, conventions, Linux, Windows, macOS, and ASan relinker jobs all pass. The broader Linux/Windows app suites were skipped by the path filter. Locally, the full relinker-only CTest suite passed 188/188. The two retail-output reruns are still the remaining validation request; I have not claimed a title fix.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-17T22:22:26Z.
Independent follow-up on exact revised head
c56cafae2e9a351559f964da45b176aed23940b4, compared with55497ed3a. Ubuntu 24.04 x86-64, glibc 2.39, GCC 13.3, Release relinker-only; production source unchanged.I generated ELF inputs using the size and alignment relationships in Dean's Astro Bot and Dreaming Sarah header excerpts, with zero-filled data and an
int3guest entry. Addresses/file offsets are translated; no title bytes, imports, TLS or title execution are involved.0x5603e8, RELRO size0x564000, next LOAD at RELRO end (Astro Bot shape)0x121380, RELRO size0x124000, next LOAD at RELRO end (Dreaming Sarah shape)Also checked three independent page-boundary controls:
0x1801, RELRO size0x2000: retained by both heads, reaches entry. The guard accepts the mapped final host page rather than requiring byte-for-byte containment.0x2001: revised head conservatively omits it, reaches entry. The previous output also reaches entry because glibc floors the protection end; this case is not counted as a reproduced loader failure.0x4000: retained by both heads, reaches entry. This rules out simply dropping every RELRO range.Each of the five layouts was converted and executed on both heads in default, fixed-base (
0x400000) and lazy modes: 30 runs, all match these expectations. All lazy outputs omit RELRO and reach entry. Input hashes stay unchanged. Revisedctest -R '^linux_gnu_segments$'also passes (1/1).This independently verifies the guard on the reported layout shapes and distinguishes it from a blanket drop or a binding-mode change. The actual Astro Bot / Dreaming Sarah startup reruns requested above remain outstanding; this is not a title-fix claim.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T22:25:24Z.
Thanks for running the 30 controlled comparisons on the exact revised head. The retained boundary controls and omitted overhang layouts support the mapping guard without implying a blanket RELRO drop. This is useful evidence for the reported header shapes; the actual Astro Bot and Dreaming Sarah startup reruns remain outstanding, so I’ll keep the title-level claim open.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-17T23:15:51Z.
Follow-up to my Oct 16 comment, which tested
90f5c3710, an older head without the coverage guard. This time it's a retail title where RELRO is fully covered: Ghost of Yōtei (PPSA26344, 01.008)eboot.bin, on headc56cafae2built as-is. Setup: CachyOS (Arch-based) x86-64, GCC 16.2.1, Release.git merge-treeagainst main5de7a46e0is clean; I did not build a merged tree.GNU_RELRO(0x1b34000, memsz0x1dc000) matches its RWPT_LOADexactly. The output keepsGNU_RELROat the same range, which ends where the next LOAD starts (0x1d10000). This is default mode:BIND_NOW, withDT_PLTGOT0x1d0d428inside the range. Neither the input nor the output hasPT_GNU_STACK, so this title doesn't test the stack half./proc/<pid>/maps30 s into a second launch,0x1b34000–0x1d10000isr--p. That is consistent with ld.so's RELROmprotect.linux_gnu_segmentspasses.That second launch later dumped core on an unimplemented sRGB compute-shader sample. The same message appears in my earlier lavapipe logs from builds without this PR.
This only checks the kept-RELRO path. The Astro Bot and Dreaming Sarah reruns are still needed.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T00:14:05Z.
Thanks for the Ghost of Yōtei follow-up. This confirms the revised relinker retains a fully covered
PT_GNU_RELROrange, the loader applies its read-only protection, and the title continues past startup until the already-known sRGB shader failure. I’ll record this as a positive retained-RELRO/title startup datapoint; it still does not cover the PT_GNU_STACK half or the two original failure titles.Imported from boykopovar/AnyPS5. Originally posted by plokmklo on 2026-10-18T02:00:41Z.
Review: COMMENTED
Independent verification (Linux x86-64, relinker-only, GCC 14.2.0, current
main0bb238b4a)Build and tests
c56cafae2is clean.linux_gnu_segments— matches the Tested section.test_linux_gnu_segments.pyfrom this PR against a relinker built frommainfails, so the test bites the regression it claims to.Behavior probes against the real binary (synthetic ET_DYN fixture: PT_LOAD RX 0..0x1000 + PT_DYNAMIC, spare headers filled with
PT_GNU_STACK, a writablePT_LOADat 0x1000, andPT_GNU_RELROinside it):main: both GNU headers silently dropped from the output.PT_GNU_STACK(flags 0x6, zero addresses) andPT_GNU_RELROrebased onto its file range inside the covering writable load (off 0x5000, vaddr 0x1000), placed in the load-sorted layout with the program-header slot accounting intact (7 → 9 headers, no slot error).Logic reading — nothing blocking found
hasWritableLoadCoverageruns on the INPUT layout while the RELRO is emitted into the OUTPUT layout. I verified the equivalence holds today: kept PT_LOADs carry vaddr/memsz through 1:1 (probe-confirmed), the synthetic extra-block load sits pastGuestLoadPageEnd, and_sortLoadHeadersreorders without shrinking ranges — so input-derived coverage implies output coverage. If a future layout change ever breaks that invariant, this is the assumption that breaks first; a line in the relinker technical-debt entry would pin it.options.LazyBindinginto the Linux patcher only; the PE and Mach-O paths never see this filter, so the scope is correct.Adjacent observation (out of this PR's scope)
PT_GNU_PROPERTY(0x6474e553) is also inside[PT_LOOS, PT_HIOS]and is still dropped with this PR applied: probed with aPT_GNU_PROPERTYmapped inside the load segment carrying a GNU property note — the header is silently omitted from the output. Same fidelity class as #6394, no intent evidence either way in the tree (no dead writer path references it). If the maintainer wants it preserved, it slots intoShouldSkipnext to the two headers here; I can send that as a follow-up PR once this one merges (verifiable with the same fixture harness).