fix(relinker): reject prefixed system-call instructions #1935
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1935"
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 Zinebyte on 2026-10-09T00:54:16Z.
What
The relinker checked the first two bytes of each decoded instruction for forbidden system calls. A prefix hid the opcode:
48 0F 05passed validation and produced an executable even though it containsSYSCALL.Check the decoded instruction's
OpcodeOffset()instead. PrefixedSYSCALL,SYSENTER,SYSRETandINT 80hnow fail with the existing error at the instruction's start address. Opcode-like bytes in immediates remain accepted, and--skip-syscall-checkretains its behavior.This addresses the scanner follow-up explicitly left out of #211. No open overlapping fix was found before implementation or on the final search.
CallSiteResolverremains outside this change.Tested
Zorin OS 18.1, Linux x86-64, GCC 13.3.0, CMake 3.28.3, Release, relinker-only build at
f145139676a48306681d3a4d5fabf83938759daf. Build parallelism: 1.executable_segmentsregression fails on the upstream binary: the REX-prefixed syscall is accepted and output is written. It passes with the fix in 0.03 s.0x1801, no output on rejection, immediate-byte decoys, and the explicit skip option.ctest --test-dir build-relinker --output-on-failure --parallel 1: 38/38 passed in 6.44 s; longest test 5.28 s.python3 tools/check_conventions.py --base origin/mainandgit diff --check: passed.Synthetic inputs only. No title or hardware compatibility testing. Windows PE output is inspected on Linux; native Windows/macOS execution and cold shared CI timing were not measured.
Checklist
main; no open overlapping implementation foundImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:20:59Z.
Review: COMMENTED
Reviewed the full two-file diff at
2381e7fc64. Using the decoder-reported OpcodeOffset makes the four syscall signatures visible after prefixes while preserving the instruction-start diagnostic; the tests also check immediate-byte decoys and the skip option. The Actions API shows this exact head has Build and Conventions runs markedaction_requiredwith no jobs, so upstream CI has not run. CONTRIBUTING requires those checks before merge; please request maintainer approval for the fork workflows. I am holding approval until those final checks run.Imported from boykopovar/AnyPS5. Originally posted by rmz-24 on 2026-10-09T11:58:45Z.
Windows run, since the description notes it wasn't tested there: Windows 11 Pro 25H2 (10.0.26200.9457), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with
BUILD_TESTING=ON.2381e7fccherry-picked onto currentmaind70b8998(applies cleanly).executable_segmentspasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T12:38:37Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/relinker/relinker/src/analysis/SyscallScanner.cppL2-3, L34-52Imported from boykopovar/AnyPS5. Originally posted by StarMrGamer on 2026-10-09T16:56:55Z.
Verified this against a clean
mainbuild (d70b8998, relinker-only, GCC 16.2.1) — the hole is real, not theoretical.Fixture whose first executable-segment bytes are the instruction, same input through both relinkers:
main2381e7fc0f 05 c366 0f 05 c348 0f 05 c367 0f 05 c3mainproduces an output for all three prefixed forms: the scan compares the first two bytes of the instruction, so a prefix hides the opcode and the syscall is never seen at all. Reading atDecodedInstruction::OpcodeOffset()is the right fix, and your head builds clean withctest38/38 here.One thing worth knowing before either of us lands: #2206 changes the same lines of
ScanCodeSectionForSyscalls. It adds a classification step that also reads the instruction's bytes, and it currently reads them at the instruction start. So the conflict resolution has to keep both behaviours:66 0f 05is accepted again.66 0f, so the protection is lost anyway.The composed form classifies at
i + opcodeOffsettoo. Whichever lands second needs the rebase; #2206 is the smaller one to adapt, and I am happy to rebase it onto this.Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-09T17:12:40Z.
Thanks rmz-24 for the Windows validation:
executable_segmentsand the full 510/510 CTest pass on Windows 11 / WinLibs GCC 15.2, including Windows PE execution, with2381e7fccherry-picked ontod70b8998. Upstream Build and Conventions have now succeeded on this PR's exact head.Thanks StarMrGamer for checking the prefixed cases and the composition requirement. #2206 adds syscall-number diagnostics in the shared scan loop; it does not replace this PR's prefix-aware
OpcodeOffset()detection fix. Neither functionally depends on the other, soDepends on: noneremains accurate. Conflict resolution needs classification at the decoded opcode position while diagnostics retain the instruction-start address, preserving both behaviors.AI-assisted review and reply.
Imported from boykopovar/AnyPS5. Originally posted by nyavana on 2026-10-10T07:39:03Z.
@Zinebyte Would these 24 additional boundary tests be useful?
github.com/nyavana/AnyPS5@ac6381e68aLinux CTest: 66/66 passed, with one internal clang-dependent skip. Two mutation checks verified the added coverage. AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by Zinebyte on 2026-10-10T13:54:29Z.
Thanks @nyavana, these look useful! The exact-boundary, out-of-segment byte and truncated-instruction cases add useful coverage. Since #1935 is now merged, a focused test-only follow-up against current main would make sense.
The diff was reviewed with AI assistance; I haven't independently run the tests. Appreciate you adding these.