fix(relinker): trap int 0x80 in a software interrupt table instead of refusing the image #10479
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10479"
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 babyhuey on 2026-10-24T02:46:36Z.
What
The syscall scan now replaces an
int 0x80withud2when it is one entry of a software interrupt table, instead of refusing the whole image. A table entry here is anint 0x80; retthat is decoded right afterint 0x7f; retand is followed byint 0x81; ret.Bedlam 2 (PPSA94003) can't be relinked on
main, with or without--trap-sdk-syscall-stubs:That offset is the
int 0x80entry of a table with one 3-byte entry for each vector from0x00to0xff, from0xc35a6up to0xc38a6(exclusive, 256 entries). Every entry isint N; retexcept vector 3, which isint3; nop; ret:No syscall number is loaded before any of the entries, so it is an interrupt dispatcher and not a system call stub. The title is a homebrew ELF without
PT_SCE_DYNLIBDATA, so the scan has no unwind ranges for it, and the rule from #8166 that skips patterns outside unwind functions doesn't apply.IsInterruptTableEntryinSyscallScanner.cppmatches the 9 bytescd 7f c3 cd 80 c3 cd 81 c3around the instruction. It also requiresint 0x7fto be a decoded instruction start, the same guard the SDK inline stubs use, so the bytes inside a longer instruction don't match. The offset goes into the scan's existing trapped list, which the pipeline already patches to0f 0b, and the scan printsTrapping int 0x80 in a software interrupt table at code offset 0x....--trap-sdk-syscall-stubsis for SDK stubs and is documented as a debugging option, and the web converter can't pass--skip-syscall-check.int 0x80, or one with a table entry on only one side, is still refused.syscall,sysenterandsysretare unchanged.docs/dev/debt/relinker.mdrecords that whether the console would run the entry as a system call isn't measured, and the rule;ud2keeps a Linux host from running it as the 32-bit system call gate. The--trap-sdk-syscall-stubsrow indocs/user/USAGE.mdnotes the exception.#9549 conflicts with this PR: it rewrites the SDK-stub trap line directly below the new branch in
ScanCodeSectionForSyscalls. The resolution is mechanical, because the two branches can't both match (cd 80against0f 05at the opcode). #10439 has merged; this head is rebased on it and keeps both sets of constants intest_syscall_number.py.Tested
syscall_scanner(Linux only) and the same cases intest_syscall_number.py, which runs on Linux, Windows and macOS:int 0x7etoint 0x82) relinks without options, and the output hasud2at theint 0x80and the neighbouring entries unchanged.int 0x80after a single table entry is still refused.mov al, imm8immediate are still refused.test_syscall_number.pyalso converts the table after fivenopbytes, so the decoded-start guard is exercised with a table that doesn't start the code.main'sSyscallScanner.cpp,syscall_scannerfails withRelinker refused int 0x80 in a software interrupt table, andtest_syscall_number.pywithmain's relinker fails on the table case (Forbidden syscall instruction at code offset 0x6).anyps5-buildCI image, Ubuntu 24.04, GCC 13, Release,BUILD_TESTING=ON):main74acfad65b3: the 5syscalltests and all 189 tests registered fromcore/relinker/pass,check_conventions.pypasses, and Bedlam 2 relinks with the trap line for0xc3726.b2a3cfc293, before the test and docs commit: the fullctest: 22 failures out of 2005, all of them lavapipe AGC driver tests plusguest_system_load_exec_standard_error, which fail in this container onmaintoo. No relinker test fails.BUILD_TESTING=ON, this head: the 4syscalltests, including the newtest_syscall_number.pycases, and all 187 tests registered fromcore/relinker/pass.test_syscall_number.pyagainst a relinker built frommain74acfad65b3fails on the table case at0x6.mainthe relink fails as above. With this head it relinks with no options and prints the trap line for0xc3726. The title then starts and stops at its own check, because the game's data files aren't in the catalog package:Reaching that line with
ud2in place also shows the entry isn't executed at start-up.On Windows (RTX 3080), this head gives the same result: the relink prints the trap line, and the title exits 0 at 2.1 s after
game data missingandreturning to dashboard, status=4.maindb6af9e0fdrefuses the same relink withForbidden syscall instruction at code offset 0xc3726.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 roboterspinne on 2026-10-24T11:35:00Z.
Review: COMMENTED
Reviewed head b2a3cfc merged onto
upstream/mainaeeaefad9(2026-10-24); the merge is clean, and so are merges onto the currentmain50aa1798eand together with #10439 and #10537 (all three merged into one tree). #9549 conflicts inSyscallScanner.cpp, see below.Environment: Windows 11 Home 10.0.26200, WinLibs GCC 15.2.0 UCRT, CMake 4.3.1, Ninja 1.13.2, Python 3.13.9,
-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON, Release. My machine was under heavy unrelated CPU load, so I report targeted tests only; the relinker matrix is green on the PR.Results
syscall_number,sce_code_gaps,guest_syscall_trap,sdk_mman_syscall,input_magicpass.syscall_scanner(the C++ test holding the new cases) is registered only on Linux x86-64 (CMakeLists.txt:842-856), so I reproduced its three cases by hand withtest_syscall_number.fixture: the baseline refuses the five-entry table (cd7ec3 cd7fc3 cd80c3 cd81c3 cd82c3) at code offset 0x6,cd7fc3 cd80c3 90c3at 0x3,b0cd7fc3 cd80c3 cd81c3at 0x4 and a lonecd80c3at 0x0; the PR build converts the table with exit 0 andTrapping int 0x80 in a software interrupt table at code offset 0x6, the output holdscd 7e c3 cd 7f c3 0f 0b c3 cd 81 c3 cd 82 c3, and the other three are still refused. Identical results with #10439 and #10537 merged on top.code[opcode-3 .. opcode+5]and both bounds checks hold,recent.Containsis the same decoded-start guard the SDK stubs use (64-entry ring, theint 0x7fstart is at most two instructions back), and trapped offsets are patched to0f 0bbyRelinkerPipeline.cpp:415-417. The #8166 skip indeed does not apply without unwind ranges.check_conventions.pypasses;pr_overlap.pyreports the #9549 conflict atSyscallScanner.cppL292-294.Should fix (text)
int3for vector 3 saves one byte, not twelve). 0xc38a6 − 0xc3726 = 0x180 = exactly 128 entries, which fits only if 0xc38a6 is the exclusive end. So "oneint N; retentry for each vector from 0 to 0xff" starting at 0xc35b2 cannot all be true; the table may start at vector 4, or the start offset is misreported. Could you attach a short hexdump of the first and last entries and correct the body and the debt sentence?Nits
SyscallScannerTests.cpp, whose helpers useposix_spawn/sys/mman.h, so the windows-latest and macos-latest jobs never ran them (your own "3 syscall tests" on Windows versus 4 on Linux shows it).f7a9629e68mirrored the scanner cases intest_syscall_number.pyfor exactly this reason; adding the table, one-entry and inside-immediate cases there (it can also check the0f 0bat 0x4006) would give all three hosts coverage. Behaviour is fine, I checked it on the Windows build.--trap-sdk-syscall-stubsand the number lookup, sob8 0b 00 00 00 e8 07 00 00 00 c3 90 90 90 cd 7f c3 cd 80 c3 cd 81 c3(a numbered call into the table's entry) relinks withud2at the entry wheremainrefuses at 0x11, and the web converter (wasm/Bindings.cpp:70-76) cannot opt out. The body and the debt entry say so, and #8166 set the precedent of a debt-recorded default-path rule, butdocs/user/USAGE.md:89still says "Other syscall instructions still cause an error"; one sentence there about the table rule and itsud2(SIGILL if reached) would keep the user docs honest.trapSdkStubsline directly below the new branch), and the resolution is mechanical because the two branches cannot both match (cd 80versus0f 05at the opcode).Notes
cd 7f c3 90 cd 80 c3 ...), a prefixed66 cd 80, a non-retbefore theint 0x80entry, or a table whoseint 0x80is the first decoded entry are still refused, and two tables in one section are both trapped. If the bytes before the table misalign the decoder, the entry is not seen at all; that is pre-existing. A test with a few bytes before the table would exercise the decoded-start guard with a non-zero start.sys/amd64/ia32/ia32_syscall.c); what the console does with it from a 64-bit process is not measured, as the debt entry says.SyscallScanner.cpp, but it is based before45a2e3dd4aand no longer merges or compiles againstmain.Not checked: the Bedlam 2 image and its runs; the C++
syscall_scanneritself; a full suite; the guest-module path with a table inside asce_module; Windows or console behaviour ofint 0x80.I found no blocking issue; the code does what the body says and the counter-check holds. The one thing I would settle before merge is the table arithmetic in the body and debt entry. For disclosure: I have open relinker PRs (#10564, #10402, #10401, #10403, #10390, #10391); none touches
SyscallScanner.cpp.Written with AI assistance (Claude Code). I ran the builds, tests and fixture checks above on my Windows 11 machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:56:18Z.
Review: APPROVED
Reviewed exact head
742408f8a0361d135d6cd264e337ded4fc380462, including the scanner, both cross-platform regression sets, docs, and the author's follow-up clarifying the Bedlam 2 table bounds. The detector is byte-exact, checks that the precedingint 0x7fis a decoded instruction start, and only traps the middleint 0x80when the adjacentint 0x7fandint 0x81entries match; unmatched and immediate-byte cases remain refused. The relinker pipeline replaces only the recorded opcode withud2.The author reports red/green relinker tests on Linux and Windows and a Bedlam 2 relink on both platforms. The current hosted eligibility, conventions, labels, Ubuntu/Windows/macOS relinker matrix, and ASan checks pass; product jobs are skipped by policy. I independently ran
python3 tools/check_conventions.py --base upstream/main --head upstream/pr-10479andgit diff --check; both pass. I did not rerun the relinker suite locally.The separately reported #10439 overlap is still present in
test_syscall_number.pywhen the two current heads are combined; preserve both test additions when resolving it. #9549's scanner conflict and its mechanical resolution are documented in the PR. I found no correctness blocker in this change.Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T17:18:11Z.
Review: APPROVED
Reviewed head
742408f8a0merged ontomainb4d8e8bb3b(clean; still clean on7e4f6e0440, which has no relinker changes since). Linux, WSL2, GCC, relinker-only Release withBUILD_TESTING=ON. This covers the two things the earlier reviews list as not checked: the Linux-onlysyscall_scannercases and Bedlam 2 itself.What I ran
cteston the merged tree: 298/298 pass, includingsyscall_scannerandsyscall_number.syscall_scanner_testsandtest_syscall_number.pyagainst a relinker built frommain0119103fa9(noSyscallScanner.cppchange since) both fail atForbidden syscall instruction at code offset 0x6.cdd390a4...0c229,rc.4release):mainrefuses with--registry --to-intel, with or without--trap-sdk-syscall-stubs, at0xc3726. This head relinks it and prints the trap line. The table bytes match your dump (cd 00 c3at0xc35a6,cc 90 c3for vector 3).mainwith--skip-syscall-checkexcept for exactly 2 bytes: file offset0xc7726,cd 80->0f 0b. So the rule changes nothing else in the image.Bedlam2 trace: game data missingandreturning to dashboard, status=4, no SIGILL. Same as your run.sce_modulefiles) forcd7fc3cd80c3cd81c3. It only shows up in Bedlam 2, so the rule fires nowhere else in that set.Note (non-blocking)
mainskipped and counted them as possible data. Repro:cd7fc3cd80c3cd81c3placed atGAPwithexecutable()fromtest_sce_code_gaps.py.maingivesSkipped 1 syscall byte pattern(s) ... 0x213and leaves the bytes alone. This head givesTrapping ... 0x213and writes0f 0bthere. A 9-byte data match is very unlikely, andud2is the safer outcome if it's code. But the debt entry says "instead of failing", and the gap line above it says the others are skipped. Either one clause in the new entry about gaps, or gating the branch withfunctions.empty() || insideFunction(start), would make it consistent. Bedlam has noPT_SCE_DYNLIBDATA, so both options keep it working.Not checked: console behaviour of
int 0x80, other GPUs, Windows or macOS, and a full non-relinker build.Approving: the rule does what the body says, and the title result reproduces on Linux.
AI-assisted (Claude Code). I ran the builds, tests, relinks and the title run above.