Repository navigation
feat(relinker): execute supported scalar guest GS accesses on Windows - #11628
Felipebmaitan wants to merge 26 commits into
Conversation
…ower of two ElfReader accepted any p_align on an executable's PT_LOAD, and on the uncovered PT_SCE_RELRO it turns into one, although the gABI says p_align should be 0, 1 or a power of two. When such a segment starts on a page that an earlier segment maps with other bytes, the Linux patcher pads the output one byte at a time to the next offset congruent to its address modulo that alignment: a 3221-byte executable with an alignment of 0xfffffffffffffffb ran for 46 s, reached 12.9 GiB and failed with std::bad_alloc. Both segments are now refused, as the reader already refuses a PT_TLS alignment that is not a power of two. The guest module reader takes its headers from the same function, so the power-of-two half of its own alignment check can no longer fail and is dropped; its offset congruence check stays. A power-of-two alignment still reaches the padding, which the relinker technical debt now records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the feature commit 1bb3d0cfcb8a7cfe102b9384b8e723bca8925d32 separately from the explicitly listed prerequisite stack.
[P1] Decode address-size-32 mod=00, r/m=101 as absolute disp32, not RIP-relative. In WindowsGuestGs::Append, the mod == 0 && rm == 5 case always sets base = 0xfe (RIP-relative). But when address-size override 0x67 is present in 64-bit mode, this ModRM form uses an absolute 32-bit displacement. The runtime then adds the instruction resume address before truncating the effective offset to 32 bits (GuestGs.cpp), so e.g. 65 67 48 8b 05 00 00 00 00 reads from GS.base + (resume & 0xffffffff) instead of GS.base + 0. That can read or write the wrong guest location. The current address32-wrap fixture uses a SIB form and does not cover this special non-SIB form.
Please set the no-base sentinel for this encoding when AddressSize32 is true, preserve the 32-bit displacement as an unsigned effective offset, and add a 67 + mod=00/rm=101 execution fixture (zero displacement is enough with the existing runner's nonzero GS base). The relinker-only build is in progress locally; conventions and git diff --check pass, and the hosted Linux/Windows relinker checks currently pass. No local Windows runtime test is claimed.
|
I confirmed the encoding case with the PR-head relinker: converting |
|
Thanks, the replay design and its tests look solid. One change before this can merge: on Please keep This also depends on #11624, #11090, #11276 and #10518 landing first, as the description says. |
|
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 independently checked the new unsupported-instruction failure path. I reran the focused Linux relinker tests at this head: |
|
@oneandonlydean Addressed in 2a621e5, with the branch now at 87ef2af. Unsupported GS forms now retain the Windows validation passed: 61 focused relinker tests, the execution suite using production libc, four thread/sysarch tests, conventions and the public-header audit. New cases skip each of 16 unsupported encodings before executing supported replay; a directly launched fallback-only program also succeeds without a GS runtime dependency. Linux was not rerun because the configured WSL disk is missing. The dependency order remains unchanged: #11624, #11090, #11276 and #10518 must land first. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed current head 87ef2af9591ba4fd21148fa1e1fd862d79f24abe. The unsupported-form UD2 fallback now appears to address the separate conversion-regression concern. A blocking address-size decoding issue remains in WindowsGuestGs::Append: for mod=00, r/m=101 the code always writes base sentinel 0xfe, which makes the runtime add the instruction resume address. With a 0x67 address-size override in 64-bit mode, this encoding is absolute disp32 with no base, not RIP-relative. The runtime then truncates the sum to 32 bits, so 65 67 48 8b 05 00 00 00 00 reads from GS.base + (resume & 0xffffffff) rather than GS.base + 0. The address32-wrap fixture uses a SIB form and does not cover this special non-SIB encoding.
Please select the no-base sentinel when AddressSize32 is true, preserve the unsigned 32-bit displacement, and add an execution fixture for 67 + mod=00/rm=101 (zero displacement with the runner's nonzero GS base is sufficient). This is still outstanding from my prior review and applies to this substantially updated head.
Validation: git diff --check upstream/main...upstream/pr/11628 passes. Hosted conventions and Linux/Windows relinker jobs pass; macOS relinker and one macOS register-context job remain in progress/queued. I did not run the Windows execution suite locally.
|
Correction to my review on this head: my claim that |
MarcZX10
left a comment
There was a problem hiding this comment.
Corrected my prior address-size finding: Intel SDM confirms mod=00, r/m=101 remains RIP-relative with 0x67 in 64-bit mode and the effective address is truncated to 32 bits. The current resume-relative calculation and truncation are correct. The UD2 fallback changes also address my earlier concern. I found no remaining blocker on this head. Hosted Linux/Windows relinker, ASan and the completed macOS jobs pass; the remaining macOS checks are still pending. The author reports extensive Windows/Linux execution fixtures; I did not independently rerun those suites.
|
@MarcZX10 Following your correction, the resume-relative calculation and subsequent 32-bit truncation remain unchanged. I moved the four Fresh production libc/libkernel builds passed on Windows and native Linux under WSL. Nine Windows and seven Linux focused runtime/relinker tests passed, and all 50 normalized scalar execution dumps match between rewritten Windows and native Linux GS, including these four cases. Conventions against origin/main passed. Main b986c11 is merged. No console/title or performance verification is claimed. |
# Conflicts: # core/relinker/CMakeLists.txt
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: make replay fault recovery distinguish a memory fault from a completed replay before redirecting the instruction pointer.
What I ran
Reviewed head f013da972573fa4dfca95607f2462501d6ad2234. Read the prepared description, commit list, manifest, diff, and all changed files listed as reviewed. Read targeted decoder, exception-handler, and caller context through repo_read.py. No build or tests were run by me; the Windows results in the PR description are author-reported.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | One verified blocking defect |
| Build and tests | not run | PR reports Windows checks |
Findings
Blocking
- On an access violation during the replayed memory instruction, the pending-replay branch restores the scratch register and adds 128 to
Rsp, then redirectsRipto the original guest instruction. It returnsfalseunless the exception is the terminal UD2 (core/libs/prx/libc/src/specifics/windows/GuestGs.cpp:107-113). The caller therefore continues searching for a handler, while the exception context has already been modified. If another handler repairs the memory fault and resumes execution, it resumes at the original GS-prefixed instruction rather than the replay instruction, causing the access to fault again or run with a corrupted stack. Recover nonterminal replay faults without discarding replay state or changing the context; restore the original context only when propagating the fault.
Non-blocking
None.
Not verified
I did not run the claimed Windows build or tests, hosted checks, PS5/title execution, or physical-console behavior. I read every changed file marked included in the manifest; no changed files were excluded there. files.json was not available through the reader.
To get this to a good state
Fix replay fault handling so a recoverable memory fault can retry the replay instruction with the pending state intact, and so propagated faults do not leave a modified stack or instruction pointer. Then rerun the focused Windows replay and fault-retry tests on the new head.
|
@MarcZX10 Addressed your November 14 replay-fault finding in The native negative control fails on the old handler at the first late-handler load retry. With the fix, both Windows component runs pass 50 scalar cases, including replay-fault retries on load, store and LOCK XADD. Production reporter component coverage also checks callback-edited RIP and RAX and the original guest diagnostic on an unrepaired AV. One independent review found no blocking source issue and identified the callback-continuation coverage gap, which This remains draft for #10518 and the #10861 integration gate. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The reviewed head is 5922e359e9a3e74ad8366698f3f15bbd0e7cf4b5; the inspected replay and fault paths support the stated behavior, and no blocking defect was verified.
What I ran
No commands or tests were run. The PR description reports a native build and 52 focused CTests passed; these are author-reported results.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Replay and fault paths inspected |
| Build and tests | not run | Author reports 52 focused tests passed |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The manifest lists 24 changed files, all marked included, but the reader interface did not expose the prepared review/files/ bundle. I therefore reviewed only the prepared diff and targeted repository source ranges, not every changed file's full text. Excluded-file details were not available. Windows runtime behavior, physical-console behavior, and the reported build and tests were not independently verified.
To get this to a good state
Nothing is required.
What
Replay supported scalar guest GS memory instructions against the Windows per-thread guest GS base. Unmodeled forms retain their own-length UD2 fallback.
Address MarcZX10’s November 14 review. A first-chance fault in replay leaves the live replay RIP, stack and scratch register available to a later Windows handler. Guest fault delivery receives the original guest context and retains callback edits to the continuation. If guest delivery declines, the runtime reports the guest location without claiming the fault is fatal. The terminal UD2 restores guest state and resumes at the next guest instruction.
Preserved published history in normal merges through main
e481b135558fc4316bc3b24e7408156737eff08d. The ELF changes retain main’s covered SCE RELRO file checks and #10518’s load and uncovered SCE RELRO alignment checks.Draft pending #10518 and the #10861 integration gate. A trial merge with #10518’s current head conflicts in
ElfReaderBoundsTests.cpp. #10861’s collector and callers need to retain generated-trap continuation entries when composed with scalar replay. The overlap scan covered 2,260 open PRs with 111 shared-file or export candidates and 37 inconclusive comparisons. #18523 shares the Windows entry-stub signatures and #19470 shares the ELF checks. The scan did not identify a competing scalar replay implementation. GitHub requires upstream write access for a formal re-request to MarcZX10. The review reply is posted in the conversation.Tested
Windows x86-64 build 26300, Ryzen 7 9800X3D, WinLibs GCC 15.2 r7. The old
f013da9725replay handler failed the new late-handler test because the context had already been rewritten. The updated standalone runner passed all 50 scalar cases, including in-place retry of a load, a store and LOCK XADD.The native libc component run passed the same 50 cases plus the guest-fault callback and unrepaired access-violation checks. The callback test validates original guest RIP, RSP, scratch registers and exception address, then verifies that edited RIP and RAX take effect. The unrepaired-fault test verifies the native exception code and guest-coordinate diagnostic. The component runs used historical converter and supporting objects with freshly compiled replay and reporting changes. The current entry-stub and ELF reader sources and bounds tests also passed when rebuilt against the archived relinker support library.
One independent reviewer checked
4446f4f0c4b4a0dc2e5241f492f34cd0c90b63aa, found no blocking source problem, and identified a gap covering callback-edited continuation registers.870917228acloses that gap and the native component test passed again. The final merge changes none of the replay or relinker files reviewed.Conventions and whitespace checks pass against
origin/main. The exact-head public-header audit passed 413 libraries and 34,756 exports. The native Release CMake/Ninja build at5922e359e9a3e74ad8366698f3f15bbd0e7cf4b5completed with two compiler jobs. 52/52 focused CTests passed in 30.94 s, including standalone and production-libc scalar replay and fault retry, emitted executable and module startup, relocations, Windows entry-stub and ELF bounds, TLS coverage, and the libkernel sysarch, pthread, signal context and exception delivery tests. JUnit SHA-256b7295bd809427ee44b4d424c34b6b77ba01e0f80044ce1dee0b34393661e2708.Historical evidence remains attached to its tested revisions. The previous description recorded 23 focused Windows tests on
f013da9725. JJenkx independently tested that head on an earlier main merge. See JJenkx’s November 8 comment in this PR for the tested revisions.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)