fix(relinker): emit PT_GNU_RELRO for Linux output instead of leaving RELRO writable #10662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10662"
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 shurhundo on 2026-10-24T15:51:56Z.
What
On Linux, a
PT_SCE_RELROsegment from the original PS4/PS5 layout was never actually protected. If it overlapped an existingPT_LOADit got dropped as SCE-specific debt, and if it didn't it got turned into a plain read-writePT_LOAD. Either way, nothing made that memory read-only after relocations ran, unlike FreeBSD's own rtld, which makes the equivalentPT_GNU_RELROsegment read-only once relocations finish.ElfReadernow retypes a coveredPT_SCE_RELROintoPT_GNU_RELROdirectly, and for an uncovered one it still synthesizes aPT_LOADto map the memory but also adds a separatePT_GNU_RELROentry over the same range. The rest of the pipeline (ProgramHeaderLayoutBuilder's write-coverage check,SegmentFilter) already knew how to handlePT_GNU_RELROcorrectly, it just never received one from this path, so this is really finishing existing wiring rather than adding new logic.A guest image with more than one
PT_SCE_RELROrange now throws a clear error on Linux output instead of silently protecting only the last one, whether the ranges are disjoint, overlapping or identical: glibc's loader and LLD both track only onePT_GNU_RELROsegment per image, and combining overlapping or identical ranges into one isn't implemented either, since no observed title needs more than one range.Windows and macOS don't have an OS-loader-level equivalent to
PT_GNU_RELRO, and Linux output with--lazy-bindingcan't safely get it either without more work: the originalDT_PLTGOTregion stays writable there for the host loader's lazy PLT resolution, and whether that region overlaps a given title'sPT_SCE_RELROrange isn't verified either way.docs/dev/debt/relinker.mdnow records this gap for all three; closing it means adding aVirtualProtect/mprotectcall to the entry stub for Windows/macOS, and resolving the lazy-binding/RELRO interaction for Linux. Both are separate topics, left for follow-up PRs.Tested
On this exact head:
ctestsuite, 540/540 pass (main has grown since this PR was first opened), includingsce_relro,linux_load_bounds,program_layout_rangesandelf_reader_boundsrun together, plus the new overlapping/identical multi-RELRO regressions.program_layout_ranges_tests(covers the multi-RELRO rejection, including the two new cases) passes directly. Native execution of several other test binaries on this machine is unreliable this session due to an escalating Application Control policy block that reproduces on an unmodifiedmainbuild too, unrelated to this change.python tools/check_conventions.py --base origin/main: passespython tools/pr_overlap.py --branch fix/linux-relro-enforcement: flags the same pre-existing shared-line overlaps with other open PRs as before (an unmerged alignment-check stack inElfReader.cpp, and incidental proximity indocs/dev/debt/relinker.md); none are duplicate implementations of this fix.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T21:50:41Z.
Review: CHANGES_REQUESTED
The exact-head tests pass locally, but there is a Linux loader compatibility blocker for multiple original RELRO ranges. I constructed a local fixture with two disjoint
PT_SCE_RELROheaders and ran this PR’s relinker; the output contains twoPT_GNU_RELROheaders. glibc currently stores only onel_relro_addr/l_relro_sizewhile parsing these headers, so a later entry overwrites the earlier one and only one range is protected (see glibc dl-load.c). LLD also documents that current loaders only support onePT_GNU_RELROheader (LLD Writer.cpp). Please preserve all RELRO ranges in a form supported by the Linux loader (without widening across intervening writable data), or reject unsupported multi-range inputs clearly, and add a two-range regression. The current tests cover only one SCE RELRO header per output.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:10:49Z.
Review: APPROVED
Reviewing exact head
23e0ad626a7e4a0146233bc7e14a6d0d92ed1aca.What I ran
Results
Findings
Blocking
None.
Non-blocking
Sources
Not verified
To get this to a good state
No blocking issue remains in the reviewed head. Keep the documented unsupported output modes as follow-up work.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T07:57:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The current head merges cleanly into
main, but it conflicts with open PR #10518 inElfReader.cpp; their landing order must be agreed and recorded before this review can be cleared.What I ran
Reviewed head
4d860f88820ce0dfb22eb4ad034d9ff84a5ed023against base828ac0b2ae74aac181ba128fb59b08a1534f2041; its merge preview withmainis clean. Environment: Linux x86_64, kernel 6.1.0-54-amd64, Python 3.11.2, GCC 12.2.0. I did not build or run C++ tests locally.Results
maincore/relinker/relinker/src/parsing/ElfReader.cpp. #10518 addsPT_LOAD/PT_SCE_RELROalignment validation in the sameReadProgramHeadersblock where this PR adds RELRO conversion.main; I did not reproduce either run.Unedited output from the pairwise merge preview
Negative control
PT_SCE_RELROis converted and protected in Linux outputFindings
Blocking
ElfReader.cppalignment-check stack, but the checklist currently saysDepends on: noneand I found no agreement with #10518's author. The repository requires authors to agree which overlapping PR lands first and declare the dependency. Please coordinate that order, record it on the checklist, and rebase/resolve the resulting integration before asking for another review. If this PR must follow #10518, listDepends on: #10518; if it goes first, record the agreed order so #10518 can integrate it._outputHeadersrejects every input with more than onePT_GNU_RELROheader, while the error, PR description, and debt entry describe only multiple disjoint ranges. Please either combine overlapping/identical ranges and reject only ranges with gaps, or update the error and debt entry to state that any multiple RELRO headers are unsupported, with a test for that broader rule.Non-blocking
The reported Windows Application Control failures are not presented as regressions because the author says the same failures reproduce on plain
main; Linux GPU/console behavior is not relevant to this relinker change.Sources
PT_SCE_RELROconversion at the reviewed headNot verified
No local C++ build/CTest, Windows rerun, or console runtime test. The author-reported WSL2 test run was not independently reproduced; hosted Linux/Windows relinker jobs were still running and macOS relinker jobs were queued at the last snapshot; ASan passed.
To get this to a good state
Agree and record the order with #10518, resolve the shared-file integration, and align the multiple-RELRO guard's behavior with its documented scope. I will rerun the same relevant checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T08:29:47Z.
Review: APPROVED
Reviewed — looks good
The changes requested on the prior head are addressed, the exact current diff is coherent, and the available Linux relinker checks pass.
What I ran
Reviewed head
79a91f942c741b17e74ca52c8176d05eb35d2ff1, based on PR base828ac0b2ae74aac181ba128fb59b08a1534f2041. Previewed the PR against currentmainate8c25dd3baa6e78531d5eee067fec5cbe8af3dcf; it merged cleanly. Environment: Debian GNU/Linux 12, x86_64, Linux 6.1.0-54, Python 3.11.2, GCC 12.2.0. No local C++ build or CTest was run.Results
e8c25dd3baa6e78531d5eee067fec5cbe8af3dcf. Main's three commits since the PR base touch unrelated files.Depends on: #10518, agreeing that #10518 lands first. #10518 remains open and its head is not yet included here; the stack check reports no conflict in the individual current-main previews. Reassess integration after #10518 merges.program_layout_ranges_testspassing. I did not independently reproduce these runs.Unedited outputs
Convention check
Dependency and merge preview
Hosted checks (`gh pr checks`)
Findings
Blocking
None found in the reviewed head. The prior multi-RELRO scope mismatch is resolved: the error, debt entry, and added overlapping/identical-range tests now agree that Linux output rejects any input containing multiple RELRO ranges. The prior overlap-order concern is addressed by declaring the agreed
#10518dependency.Non-blocking
#10518remains open. The dependency order is now explicit; wait for it to land before rebasing/integrating this PR, then recheck the resulting head.Sources
Not verified
No local build/CTest, Windows test reproduction, macOS test, or physical-console behavior. Hosted macOS relinker jobs were pending at the last check. The author-reported WSL2 and Windows results were not independently reproduced.