fix(relinker): refuse branches into trapped guest GS instructions on macOS #7706
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7706"
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 Destroyers212x on 2026-10-19T01:52:05Z.
What
#6458 replaces every guest instruction with a GS prefix by
UD2and NOP padding in macOS output. The guest TLS stubs on the same path refuse a direct branch whose target is inside the instruction they rewrite ("Branch enters a guest TLS instruction",MacOsImage.cpp). The GS-trap loop has no such check. So a branch into the middle of a GS-prefixed instruction is converted, and the code at its target is overwritten:Unsupported macOS guest TLS instruction (bytes: 65 b8 2a 00 00 00).main: converted to74 01 0f 0b 90 90 90 90 c3. The taken branch now runs0b 90 90 90 90 c3(or edx, [rax-0x3c6f6f70], which also consumes theret) instead ofmov eax,42; ret. A path that never touched GS executes a different memory access instead of faulting at the trap.Branch enters a guest GS instruction, using the sameBranchTargetstest as the TLS stubs. Traps with no branch into them are unchanged.test_macos_gs_traps.pygains this case. It fails on currentmain(the relinker converts the image) and passes with the change.Overlap: #6802 and #7450 change other parts of
MacOsImage.cpp. #7332, the macOS integration branch, carries #6458's trap code without this check. #8063 stops trapping GS instructions with no memory operand, so the regression case here branches into a GS memory access (65 48 8b 0c 25 78 03 00 00); the check passes with this branch and #8063 merged together, apart from a textual conflict in the test file.Tested
Apple M1, macOS 26.6.2, AppleClang, relinker-only Release builds:
-DCMAKE_OSX_ARCHITECTURES=x86_64, tests under Rosetta: 199/199 pass.test_macos_gs_traps.pyfails against the unfixed build and passes with the fix.python3 tools/check_conventions.py --base origin/mainpasses.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 AasishDairelSahayaGrinspan on 2026-10-19T19:35:31Z.
Sequencing note: a change that stops trapping a GS prefix on an instruction with no memory operand (
65 90,65 48 89 c8,65 b8 ...) is up as #8063. With it, this PR's new case74 01 65 b8 2a 00 00 00 c3converts instead of being refused, because65 b8 2a 00 00 00has no memory operand. A memory-operand form keeps the case, e.g.74 01 65 8b 04 25 30 00 00 00 c3. If #7706 merges first I will rebase #8063 and use the memory form; if #8063 merges first, this test case will need the same adjustment.