Repository navigation
fix(relinker): mask embedded data tables in inter-FDE gaps - #8076
oneandonlydean merged 8 commits into
Conversation
|
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.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
I checked current head |
|
Verdict: defect. The mask runs past the data table into decodable code, so a forbidden syscall there is no longer refused. For an embedded data table, Probe image:
Both results are the same for the Linux default and Other results:
AI-assisted: yes (Claude Code); results above were run on this machine. |
|
Follow-up full Linux validation on unchanged head |
|
I checked this against the current head Please limit masking to the confirmed table bytes and preserve scanning after the table, with a regression fixture containing an embedded undecodable table followed by decodable code with a forbidden syscall before the next FDE. |
|
Adding one case to @wachi35676's finding, because ending the mask where decodable code resumes doesn't cover it. On A callback routine without an FDE fits all four: its address is taken with Could the mask cover only bytes that actually fail to decode from the table start, i.e. stop at the first offset where linear decoding succeeds through to padding or a decodable instruction run, and keep a region whose first bytes decode as code in the strict scan? A test with a Separately: the gate titles' executables (and the homebrew wachi35676 listed) have |
|
Thanks, the bounded table end and the callback case look right, and the relinked output for our two test titles is byte-identical to One problem before merge: the relink takes much longer. For the PPSA21564 executable, The cause looks like Could you compute the padding-run ends once per gap (one backward pass gives, for each offset, where the run of padding bytes starting there ends), so that |
|
Windows run of head Host: Windows 11 Pro 26220, Ryzen 7 5700X, NVIDIA GeForce RTX 4070 driver 596.21, WinLibs MinGW-w64 GCC 15.2 r7, Release, relinker-only build (
The per-title median ratio is 3.06x (default) and 1.57x (
Not checked: Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
@brainiac91 I checked the rebase and the backward gap analysis. The scanner ranges stay SCE-only and the repeated suffix walks are gone, but the new trailing state loses one case the old walk preserved. For Could you preserve the old state through this case and add a regression with a table prefix followed by that suffix, requiring the mask to end before the syscall and the relinker to refuse it? Please cover both the executable and guest-module routes and keep the large-gap test. I checked the byte sequence with objdump and replayed the source recurrence; I have not run the full relinker counterexample because the shared build slot is occupied. The timed output comparisons against current main on both targets are still needed after the fix; the synthetic timing result does not replace them. |
|
The recurrence issue now reproduces through both actual conversion routes at exact head I reused the existing
The corrected cases return exit 2 with The existing This is synthetic conversion evidence on macOS arm64; I did not execute the generated guest code, use title/proprietary inputs, or test a combined-main tree. |
trailing[next] is Padding for an instruction that starts with 00 or CC even when the rest of its bytes are code, so it is not the same as padding[next]. The recurrence treated the two as interchangeable and overwrote the trailing state of a syscall that precedes such an instruction, which let the fallback extend the mask over it and made both conversion routes accept the gap. Decide from the trailing state whether the successor is padding. The regression covers the table helper plus the executable and guest module routes; without the correction the executable and module conversions succeed instead of refusing syscall 9.
|
Good catch, both of you. Added the helper test plus executable (SCE and SysV) and guest-module regressions. Reverting the fix makes the executable and module cases convert instead of refusing syscall 9, so they guard the real path. 301/301 ctest, conventions and The real-title timings are still outstanding. No title inputs here, so PPSA21564 / PPSA99420 need a run on your side. |
|
Verified I do not require an additional large-gap rejection variant for this correction. The retained acceptance fixture exercises the cached analysis and trailing retries; I found no concrete uncovered superlinear path, and the earlier rejection-path proof remains available. These are synthetic macOS arm64 unit/conversion checks, using production-identical binaries for the Python suites and rebuilding the new C++ test against matching sources. They are not a combined-main build, generated guest execution or hosted CI. I do not have the requested title inputs, so I cannot supply PPSA21564/PPSA99420 timings; those measurements remain outstanding. |
|
Thanks for re-running both trees — that closes it on my side too. Agreed on the large-gap variant; I'll leave the current fixture as is. Only the PPSA21564 / PPSA99420 timings are left, and none of us has the inputs, so @oneandonlydean or @screamm will need to run those when a build slot is free. |
|
@brainiac91 Thanks for tracking this down. Two things I'd like to see before this goes in:
|
|
The second condition also reproduces through the actual relinker routes at That is undecodable table data, padding, All nine syscall fixtures currently convert successfully: SCE executable, SysV executable and guest module, each targeting Linux, Windows and macOS. All nine data-only controls also succeed. Our earlier This is therefore a pre-existing table-classification limitation preserved by the optimization, separate from the recurrence regression fixed in These are synthetic conversion checks on macOS arm64, without guest execution, proprietary/title inputs or a combined-main build. The original |
Every pending gap target walked the whole unwind function vector, so a large executable cost targets x functions. Sort and merge the ranges once, then use upper_bound for each target.
A gap that holds a table, padding and then a syscall stub followed by non-padding data classified the stub as invalid, so the mask ran to the end of the gap and hid the syscall from the scan. Mark any instruction that ends control flow as a terminator, which stops the mask before that block. Covered by the helper test and by the SCE, SysV and guest-module conversion tests, which convert before the change and refuse syscall 9 after it.
|
Both done, head Binary search is in: the unwind ranges are sorted and merged once, then upper-bounded per pending target. Synthetic 1.2 MiB executable, 20,000 functions and 20,000 gap branch targets, median of five runs on this machine: 2.159 s before, 0.228 s after. The helper alone at 40,000 functions and targets goes 6.935 s to 0.190 s. I have no PPSA21564/PPSA99420 inputs here, so that is as close to a title comparison as I can get. The mask now ends before any block that ends in a jump, return, trap or syscall, even when non-padding data follows it. @plexerPK's exact bytes are in the helper test, both executable routes and the guest module; all of them convert before the change and refuse syscall 9 after it. One trade-off: table bytes that look like a padding run followed by a terminator block can now end the mask early, which surfaces as a decode failure instead of a hidden syscall. Say the word if you would rather refuse the candidate in that case. 301/301 ctest, conventions and diff check clean. |
|
@brainiac91 On the timings: I don't have PPSA99420, so the relink timing we can run is PPSA21564 (main vs this PR, Linux and Windows, plus a byte-compare of the output). I'll run it on the head that addresses the two points in my earlier comment and post the numbers here. |
|
@brainiac91 Thanks, the binary search is exactly what I meant and the syscall-stub case now works. One new concern with ending the mask at any terminator: a position now counts as a trailing code block when valid decoding from just after a pad run reaches any ret, jump, trap or syscall, even if non-padding data follows. Real tables have 00/cc/90 bytes, so this can trigger inside a table. As a rough check I generated the standard Whirlpool table (2 KB, same layout as the one in ubiservices) and swept the bytes after each pad run with objdump: two of the 15 runs, around offsets 952 and 957, lead into a valid chain that ends in a ret. If the relinker decoder agrees, the mask would stop there and leave the rest of that table unmasked, which is the original failure. I could not run the real relinker decoder or ubiservices.prx, so please check it. Could you (1) tighten the trailing-block test, for example by requiring a 16-byte aligned start after at least one pad byte, or a minimum run of valid instructions; (2) add a test that uses a realistic table containing 00/cc/90 and ret-like bytes and asserts the whole table is masked; and (3) relink the real ubiservices.prx on this head? |
|
Verified exact head The merged-range lookup matches the previous linear membership predicate in 1,320,000 synthetic comparisons using the extracted source, including unsorted/nested/adjacent/empty/reversed ranges, endpoints and uint64_t limits. I found no material issue in the scoped change. Conservatively stopping the mask when bytes look like terminating code is consistent with refusing ambiguous input; I am not requesting a different policy without a concrete failing case. This is macOS arm64 synthetic conversion/unit evidence, not generated guest execution or a combined-main build. The real-title timing and output comparisons remain separate and outstanding; I have no inputs to supply them. |
A chain of table bytes that decodes to a return after a padding run looked like trailing gap code and stopped the mask inside a real table, which hands the rest of it back to the decoder. Truncating now needs the block to contain a syscall, or to end where the gap turns into padding, so a 2 KiB table with 00/cc/90 runs and return-like bytes stays masked.
|
Reproduced and fixed, head A 2 KB Whirlpool-style table with I tightened it by requiring the block to hold a syscall, or to end where the gap turns into padding, rather than by alignment: an aligned pad run inside table data can still decode to a ret, and requiring alignment would hide unaligned stubs.
I can't relink ubiservices.prx - no title inputs here, so PPSA21564 is yours. 301/301 ctest and conventions clean. |
|
Thanks for the sweep. Head moved to |
|
Checked I also reran both external nine-route matrices: 18 syscall refusals (exit 2, syscall 9, no output) and 18 successful data controls across SCE executable, SysV executable and guest-module conversion to Linux/Windows/macOS. Thus both reported syscall cases remain corrected. The interval-membership implementation is unchanged. One evidence boundary: the added 2 KiB test repeats a synthetic row and inserts return chains; it is not the complete standard Whirlpool table. Its red/green result is established, but it does not by itself establish the reviewer's whole-table reproduction or real ubiservices conversion. Those checks and title timings remain outstanding. This is macOS arm64 synthetic conversion/unit evidence, with no generated guest execution, title inputs or combined-main verification. |
|
Closed the whole-table gap on my side with the real table, not a synthetic one. I took the standard 2 KiB Whirlpool With the reported The harness is scratch and stays out of the tree - I did not want 2 KiB of constants in the suite, and the committed 2 KiB test already pins the boundary rule. |
|
Re-checked head All the gap cases I have are refused. I added three aimed at the new rule (end the mask only at a block that holds a syscall). The probe image is unchanged (
The earlier cases (
AI-assisted: yes (Claude Code); results above were run on this machine. |
…osetta conversion The syscall scans mask the tables FindRelativeJumpTables finds in executable segments (trailing relative jump tables and, since boykopovar#8076, LEA-referenced data tables between unwind functions), but the Intel and Rosetta converter still decodes the whole segment and stops on table bytes such as 0F 78 ("Cannot decode instruction"). Compute the table ranges once, before conversion, with a DataTableRanges helper that Conversion and the guest module builder call. The converter scans a copy with those ranges masked, drops every instruction that overlaps one, and keeps stub windows and islands from spanning them. The later syscall scans reuse the same ranges; the pipeline computes them itself only when Conversion passes none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…osetta conversion The syscall scans mask the tables FindRelativeJumpTables finds in executable segments (trailing relative jump tables and, since boykopovar#8076, LEA-referenced data tables between unwind functions), but the Intel and Rosetta converter still decodes the whole segment and stops on table bytes such as 0F 78 ("Cannot decode instruction"). Compute the table ranges once, before conversion, with a DataTableRanges helper that Conversion and the guest module builder call. The converter scans a copy with those ranges masked, drops every instruction that overlaps one, and keeps stub windows and islands from spanning them. The later syscall scans reuse the same ranges; the pipeline computes them itself only when Conversion passes none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Resolves #7547 ([Relinker] Crash in CodeInstructionCollector during PRX relinking on ubiservices.prx).
Compilers place constant data tables, such as the OpenSSL Whirlpool table in
ubiservices.prx, in inter-FDE gaps after function code and reference them with a RIP-relativeLEA.FindRelativeJumpTablestreated thatLEAtarget as gap code, so the syscall scan decoded the table bytes andCodeInstructionCollectoradded them as CFG roots;0F 78is not a valid opcode, so conversion failed.LEAtarget are padding, no direct branch targets it, and its linear decoding fails; mask it with0x90in the scan buffer inRelinkerPipelineandGuestModuleBuilder, and keep it out of the CFG roots inCodeInstructionCollector.PT_GNU_EH_FRAMEas well asPT_SCE_DYNLIBDATAto locate those gaps, but keep the syscall and call-site scan rangesPT_SCE_DYNLIBDATA-only, so images without it stay strict.GapAnalysiscaches the per-byte padding, trailing-code and syscall state in one backward pass per gap, so the analysis is linear in gap size.Supersedes and replaces #8042.
Tested
main1f68b1f77; linear history, 8 commits.ctest --test-dir build-relinker: 301/301 passed.control_flow_graph,sce_code_extent,sce_module_code_extent,executable_segments: 4/4.CheckLargeZeroGaps(32 gaps of 64 KiB, 2 MiB) and the decoded-padding-suffix and stub-before-data regressions were verified to fail when their fixes are reverted. A 2 KiB table with00/cc/90runs andmov rax,rax; retchains after them masks whole, and fails against the earlier terminator rule.C0table (constants from Linuxcrypto/wp512.c, public domain) in a scratch harness on this head: with the reported0F 78 33 1Eat theLEAtarget the mask covers all 2048 table bytes and the syscall scan finds nothing in them, while amov eax,9; syscall; retstub behind the table is still seen and refused;C0on its own decodes linearly to +2046 with no0F 05/0F 34/0F 07/CD 80pair, so it is left unmasked.tools/check_conventions.py --base origin/mainandgit diff --check: clean.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)