feat(relinker): make PT_SCE_RELRO read-only in macOS output #18373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18373"
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 SHOnnay on 2026-11-11T12:37:55Z.
What
macOS output left every
PT_SCE_RELROrange writable after relocation (debt, "macOS entry stub has no equivalent"). It now makes those pages read-only after dyld's fixups and before guest code runs, asPT_GNU_RELROdoes on default Linux output.PT_GNU_RELROheaders thatElfReaderproduces fromPT_SCE_RELRO, filtered by the same writable-load coverage check the Linux layout uses.hasWritableLoadCoveragemoves out of the anonymous namespace asHasWritableLoadCoverage. Pages are rounded as glibc's_dl_protect_relrorounds them: start and end both rounded down to 4 KiB, so a range under one page protects nothing._mprotectis bound into a new__APS5DATAslot. Each range getsmprotect(start, size, PROT_READ), and a non-zero return reachesud2.__APS5TEXTruns after the--trace-importsprologue, so traced slots inside RELRO are written before protection. It then jumps to the existing entry stub. The stub savesrdi,rsi,rdxandrcxand keeps the call 16-byte aligned. The__TEXTjump and the patching of the trace prologue's exit become one pre-entry chain.__mod_init_funcstub after TLS import stores and beforemodule_startandDT_INIT_ARRAY. That is the order ld.so uses forPT_GNU_RELRO.--lazy-bindingoutput.Unlike Linux output, macOS output protects every range. Linux throws on more than one range because the loader tracks only one
PT_GNU_RELRO; here each range gets its own call.Windows (
VirtualProtect) is not part of this PR because it cannot be run on this machine.Tested
macOS 27 on Apple M1. Relinker-only Release build, AppleClang. Relinked x86-64 output ran under Rosetta.
ctest --test-dir build-relinker -j 4: 779 of 779 passed, including the newmacos_sce_relro.macos_sce_relroexecutable cases. The guest entry jumps through a rebased slot inside the RELRO range, so exit 42 shows dyld's rebase landed before protection. Results:--trace-importswith a replacing hook exit 77,--trace-importsplus a store into RELRO SIGBUS.macos_sce_relromodule case. A guest module with RELRO over its data page is loaded withdlopen.Readreturns 7 through the rebased slot;Writefaults._mprotectis bound when a protectable range exists. It is not bound with no RELRO, or with RELRO shorter than a page. Hosts that cannot run x86-64 Mach-O check only this; macOS CI asserts that it executes.main1b485ff745, same machine:Writereturns 9. Both writes succeed.pr_overlap.pyfound no overlap among the 49 pull requests it could merge. It could not compare 20 that conflict withmain. I read the RELRO,mprotectand entry stub hunks of each:PT_SCE_RELROerrors.mprotectin unrelated code.MacOsImage.cpp.None protects RELRO on macOS. A rebase conflict in
MacOsImage.cppwith #10861 is possible.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:44:28Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head
2cbb4d05dc20e16f460d964d919dfddabbb7adab, basemain. Read-only review of the diff and of the repository at the head, throughrepo_read.py. No build, no test run, no write to the repository.Commands
Results
macos_sce_relrotestrdi,rdx,rcxare saved and restoredsub rsp, 8keep 16-byte alignmentPROVIDERandPT_LOADnotFindings
Blocking
None.
Non-blocking
core/relinker/CMakeLists.txt:1195: the 30 s CTestTIMEOUTapplies to the wholetest_macos_sce_relro.pyrun. That run makes 11 relinks, a module relink, 9 binary runs, anxcrun clangcompile and two module runs. It passed on the author's M1, but a slower CI runner or Rosetta could exceed 30 s. A longer timeout for the native path would remove that risk.core/relinker/elfpatcher/src/macos/MacOsImage.cpp:544: aPT_SCE_RELROpage outside a writable Mach-O segment now fails the whole macOS relink. Before this change, such an input relinked without protection. The description says this is intended (fail closed), but no title was checked against it. The PR should say whether any shipping title reaches this path.Not verified
mprotectunder Rosetta, Intel hardware) was not run. Real titles were not checked.core/relinker/elfpatcher/src/macos/MacOsImage.cpp(1074 lines) was read through the diff and at the ranges listed above, not in full.core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cppwas read the same way.CMakeLists.txt, the header,docs/dev/debt/relinker.mdand the new test were read through the diff; the new test is new, so its diff is its full text. Blocking judgements rest on the changed lines, which I read in full.PROVIDERandPT_LOADimported by the new test, and the internals oftest_sce_relro.fixture, were not checked.--lazy-bindingon macOS was not checked.To get this to a good state
Nothing is required. The non-blocking points above are optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T01:37:32Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes consistently protect eligible macOS RELRO ranges after fixups and import tracing, and no blocking defect was verified.
What I ran
Reviewed head
bacf5493d9197747a42c8fe7d12e341880676e0d. I did not run commands or tests; this review session provided reader tools only. The author reports 779 of 779 tests passed on macOS 27 with Apple M1 and AppleClang; I did not verify that run.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
The reported test run, macOS runtime behavior, and Linux and Windows host behavior were not independently verified. No files were excluded by the manifest. Reviewed files:
core/relinker/CMakeLists.txt,core/relinker/elfpatcher/include/elfpatcher/general/ProgramHeaderLayoutBuilder.hpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp,core/relinker/elfpatcher/src/macos/MacOsImage.cpp,core/relinker/relinker/tests/test_macos_sce_relro.py, anddocs/dev/debt/relinker.md.To get this to a good state
Nothing is required. The author-reported test results are optional context and were not independently checked.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T08:50:29Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at
d4e92abe4f9ba3a941a218c263f28a0538fc9b2badds macOS RELRO protection after fixups and import tracing; I found no verified blocking defect in the changed code.What I ran
No build or tests were run. The author reports a macOS Release build and 779 passing tests; those results were not independently verified.
Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the build, tests, convention check, or overlap check. I did not verify behavior on macOS hardware, Windows or Linux hosts, or real titles. All six files listed as reviewed in the manifest were read:
core/relinker/CMakeLists.txt,core/relinker/elfpatcher/include/elfpatcher/general/ProgramHeaderLayoutBuilder.hpp,core/relinker/elfpatcher/src/general/ProgramHeaderLayoutBuilder.cpp,core/relinker/elfpatcher/src/macos/MacOsImage.cpp,core/relinker/relinker/tests/test_macos_sce_relro.py, anddocs/dev/debt/relinker.md. No changed files were excluded by the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T05:15:36Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
16281ae57e7e7bb872b01bacc1cb004699c0d535. No shell commands or tests were run; the repository reader was used to inspect the prepared review materials and changed source files.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No changed file was excluded: all five files listed in
review/manifest.jsonhave full text in the prepared files and were read. Tests and behavior were not independently run; the macOS 27/Apple M1 test results in the PR description are author-reported. Intel Mac hardware, Linux and Windows hosts, and real titles were not tested per the description.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:41:13Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed source and reported checks support merging.
What I ran
Reviewed head
79fa3163238bccd7d5ed7d600fff75584302a524using the pinned repository reader. No build or test command was run in this session.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the build or tests, and did not verify the author reported macOS execution. No changed files were excluded;
files.jsonlists all six changed files as included, and all six were read. The review folder’sfiles.jsonitself was not available through the reader.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:58:07Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ranmacos_sce_relroon Linux. It passed its output checks for the read-only segment. Native macOS behavior remains outside this run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.