fix(relinker): make PT_SCE_RELRO read-only in Windows output as FreeBSD rtld does #18523
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18523"
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 Ragbie on 2026-11-11T20:03:31Z.
What
Windows output left every
PT_SCE_RELROrange writable after startup (debt, "the Windows and macOS entry stubs have no equivalent of it at all"). The entry stub now makes each range read-only withVirtualProtect(..., PAGE_READONLY, ...), in the order and rounding of FreeBSD 11.4's rtld (libexec/rtld-elf/rtld.c):relocate_object(:2917). The executable's ranges are protected after the guest initializers and before control enters the ELF entry, as rtld does for the main program afterobjlist_call_init(:786,:798).WindowsLoadImage::GetRelroRangestakes the lastPT_GNU_RELROheader thatElfReaderproduces fromPT_SCE_RELRO. rtld keeps one range per object and overwrites it for each header (:1459-1460), so with several headers only the last is protected; Linux output throws in that case instead. The range is rounded as rtld rounds it: the start down to a page, the size up to whole pages. Pages are 4 KiB here and 16 KiB on the console. The range is left writable unless every page it covers is writable in the image, ashasWritableLoadCoveragedoes for Linux output.VirtualProtectfails, the stub printsFAIL: cannot make a RELRO range read-onlywithGetLastErrorand raises, as the other startup failures do. rtld fails the load in the same case (:5338).--trace-importsthunks. Unresolved lazy imports get their stubs at relink time, and the TLS resolver only reads. Deferred guest initialization writes only the.ginittable, which is in its own section and not part of a RELRO range. So--lazy-bindingkeeps protection on Windows, unlike Linux output.relinker.mdentry now lists only macOS and Linux--lazy-bindingoutput, and records that 4 KiB rounding can differ from the console's 16 KiB pages in both directions. The multiple-range entry notes that Windows protects only the last range. The overlapping-PT_LOADentry no longer says Windows has no RELRO step.Overlaps: #18373 (macOS) changes the same
relinker.mdentry; whichever lands second drops its target from the list. #15245 and #11628, #11661, #11689 and #11698 add lines next to the ones this PR adds inWindowsEntryStubBuilder.hpp(Buildsignature),GuestRuntime.hppandWindowsLoadImage.hpp. #3965, #7594 and #7704 change other hunks ofWindowsEntryStubBuilder.cpp.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0, relinker-only Release build.
sce_relrogains Windows run cases. The executable's entry stores one byte, then jumps through a relocated slot inside the range to a function that returns 42. A guest module'sDT_INITstores one byte into its own range.main, all five cases exit 42: covered and standalone executable ranges, the guest range, and the two writable controls.0xc0000005. The same store into a plain read-write page, in the executable and in the guest, still exits 42. The original cases still exit 42, so the relocated slot is read after protection.0xc0000005.ctest --test-dir build-relinker: 867 of 867 passed.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-11-21T04:35:50Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The RELRO range calculation can leave part of an unaligned range writable because it rounds the size without accounting for the starting address’s page offset.
What I ran
Reviewed head
92233aa31a0c8eced17669da4931e6aadffe6085. I read the prepared description, commits, manifest, diff and file listing, then usedrepo_read.pyto inspect changed code and relevant context. I ran no build or tests.Results
Negative control
Could not run a negative control; no test execution was performed.
Findings
Blocking
GetRelroRangesfloors the start to a page at line 163, but computes the number of protected pages fromMemorySizealone at line 164. For a range that starts partway into a page, the rounded-up size must include that starting offset; if it crosses a page boundary, the current calculation can omit the last page. The emitted protection range can therefore fail to cover the whole RELRO range. Calculate the rounded end from the range end (or include the start’s page offset in the size). Changed line:core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp:164. Source at reviewed commitSources
Not verified
No build or tests were run, and console behavior was not verified. Read the prepared review documents and diff, plus targeted source ranges in all 10 changed files; the complete repository file texts were not all read. The file listing showed all 10 changed files included.
files.jsonwas not available through the reader.To get this to a good state
Fix page-count rounding to cover the complete range for unaligned starts, add a test for an unaligned range that crosses a page boundary, then run the relevant tests on the new head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:58:02Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONand ransce_relroon Linux. It passed the Windows output checks for the protected segment. Native Windows execution 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.