Skip to content

feat(relinker): support VEX guest GS memory accesses - #11698

Draft
Felipebmaitan wants to merge 81 commits into
boykopovar:mainfrom
Felipebmaitan:feat/windows-guest-gs-vex
Draft

Felipebmaitan wants to merge 81 commits into
boykopovar:mainfrom
Felipebmaitan:feat/windows-guest-gs-vex

Conversation

@Felipebmaitan

@Felipebmaitan Felipebmaitan commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Replay bounded C4/C5 VEX guest GS memory moves through the protected Windows GS frame. The replay preserves effective addresses, native alignment and transfer widths, and upper YMM lane behavior. Unsupported encodings retain their own-length UD2 fallback. Conversion and startup are host-AVX-independent. Reaching VEX replay without OS-enabled AVX state reports an illegal instruction at the original guest RIP with the stack and registers restored.

This follow-up adds four cases for C4/C5 RIP-relative VMOVDQU loads borrowed by a short GS instruction, covering both 128-bit and 256-bit forms. It merges the published #11689 head faf9d25c09f105a84ed01c3c9785651d9d989281, which adds coverage for a borrowed EBX write feeding an SSE load or store through RBX. The candidate changes two Python tests relative to the previous published VEX head. VEX increment over #11689.

This PR stays draft targeting main. The #11661 worker ended with its current-main integration unpublished, so the updated short replay and scalar replay-fault work are still pending in the published stack. The merge preview against main c8f72e905cce039a05970ed39d2373f770217901 has inherited conflicts in the ELF reader, ELF bounds tests and libc/libkernel debt. #10518 and #10861 remain open. The shared entry-stub signatures with #15245 still need merge-order coordination.

Tested

On native Windows 11 Pro build 26300, x86-64 Ryzen 7 9800X3D, 79/79 focused tests passed with the test scripts at 74746df3147c84663716e32f0fd7dc920cbe2ed8 and archived WinLibs GCC 15.2 Release binaries. Hashes for 774 archived relinker, libc, libkernel and build inputs matched the previous published VEX head f16c9e062bd1d7607e1b3c976a6071904a81960c after line-ending normalization. The run covered scalar and short GS replay, SSE and VEX faults and fallback, synthetic --no-avx and cached lookup, production-libc replay, executable and module startup, entry roots and bounds, relocations, TLS, deferred dependencies and sysarch/pthread. Both runners passed 81/81 VEX and 85/85 SSE address cases.

Negative controls shifted the four new VEX replay displacements by one byte. Each failed the expected YMM-state assertion. Conventions passed against origin/main using both checker versions, and the diff whitespace check passed. The function-name overlap scan found no matching open implementations for the queried names. Existing shared-file and merge-order work remains documented above.

One independent reviewer inspected f16c9e062b..74746df314, verified both published ancestors, checked the archived source correspondence and JUnit results, and reran the four displacement controls. They found no blocking issues. The public-header audit verified unique declarations and umbrella coverage for 407 libraries and 30,931 exports.

The earlier contributor-reported 50-test production run and hosted checks apply to f16c9e062bd1d7607e1b3c976a6071904a81960c. Fresh current-main binaries, hosted production CI and collaborator re-review remain gates. Physical non-AVX hardware and title execution remain unverified.

Checklist

lulebo and others added 26 commits October 24, 2026 16:31
…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>
# Conflicts:
#	docs/dev/debt/relinker.md
# Conflicts:
#	core/relinker/relinker/tests/test_windows_guest_gs.py
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 6149 core/relinker/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7173 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7531 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 7715 docs/dev/debt/libc.md
PR 8605 docs/dev/debt/libkernel.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9302 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9938 docs/dev/debt/libkernel.md
PR 10007 docs/dev/debt/libc.md
PR 10409 docs/dev/debt/libc.md
PR 10558 docs/dev/debt/libkernel.md
PR 11215 docs/dev/debt/libkernel.md
PR 12130 core/libs/prx/libkernel/System/src/Exception.cpp
PR 12184 docs/dev/debt/libc.md
PR 12678 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 12849 docs/dev/debt/libc.md
PR 12910 core/relinker/relinker/tests/test_tls_function_coverage.py
docs/dev/debt/relinker.md
PR 14103 docs/dev/debt/libkernel.md
PR 14108 docs/dev/debt/libkernel.md
PR 14241 docs/dev/debt/relinker.md
PR 15040 docs/dev/debt/libkernel.md
PR 15642 core/relinker/CMakeLists.txt
docs/dev/debt/relinker.md
PR 15973 docs/dev/debt/libc.md
PR 16214 docs/dev/debt/libc.md
PR 16516 docs/dev/debt/libc.md
PR 16560 docs/dev/debt/libc.md
PR 16790 docs/dev/debt/libkernel.md
PR 16826 docs/dev/debt/libkernel.md
PR 16919 docs/dev/debt/libc.md
PR 16924 docs/dev/debt/libc.md
PR 16944 docs/dev/debt/libc.md
PR 16949 docs/dev/debt/libc.md
PR 16975 docs/dev/debt/libc.md
PR 17259 docs/dev/debt/libc.md
PR 17261 docs/dev/debt/libc.md
PR 17277 docs/dev/debt/libc.md
PR 17296 docs/dev/debt/libc.md
PR 17331 docs/dev/debt/libc.md
PR 17539 docs/dev/debt/libc.md
PR 17555 docs/dev/debt/libc.md
PR 17556 docs/dev/debt/libc.md
PR 17557 core/relinker/CMakeLists.txt
docs/dev/debt/libc.md
docs/dev/debt/relinker.md
PR 17558 core/relinker/CMakeLists.txt
docs/dev/debt/libc.md
docs/dev/debt/relinker.md
PR 17568 docs/dev/debt/libc.md
PR 17578 docs/dev/debt/libc.md
PR 17607 docs/dev/debt/libc.md
PR 17610 docs/dev/debt/libc.md
PR 18190 core/libs/prx/libkernel/Module/src/DynamicLoader.cpp
PR 18324 core/libs/prx/libkernel/System/src/Exception.cpp
docs/dev/debt/libkernel.md
PR 18373 core/relinker/CMakeLists.txt
PR 18449 core/relinker/CMakeLists.txt
PR 18462 docs/dev/debt/libkernel.md
PR 18523 core/relinker/domain/include/domain/GuestRuntime.hpp
core/relinker/elfpatcher/include/elfpatcher/windows/WindowsEntryStubBuilder.hpp
core/relinker/elfpatcher/include/elfpatcher/windows/WindowsLoadImage.hpp
core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
docs/dev/debt/relinker.md
PR 19470 core/relinker/relinker/src/parsing/ElfReader.cpp
core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
PR 21464 core/libs/prx/libkernel/System/src/Exception.cpp
PR 23636 core/relinker/CMakeLists.txt
PR 23747 core/relinker/CMakeLists.txt
PR 23781 core/relinker/CMakeLists.txt
PR 23842 core/relinker/CMakeLists.txt
PR 23861 core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp
PR 24377 docs/dev/debt/libc.md
PR 24472 core/relinker/CMakeLists.txt
PR 24915 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
PR 25483 core/relinker/CMakeLists.txt
PR 26069 core/libs/prx/libkernel/System/src/Exception.cpp
PR 26232 core/relinker/CMakeLists.txt
PR 27255 core/relinker/elfpatcher/include/elfpatcher/windows/WindowsLoadImage.hpp
core/relinker/elfpatcher/src/windows/WindowsLoadImage.cpp
PR 27801 core/libs/prx/libkernel/System/src/Exception.cpp
PR 27809 core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
PR 27825 core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp
PR 27848 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/include/elfpatcher/windows/WindowsEntryStubBuilder.hpp
core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp
core/relinker/elfpatcher/src/windows/WindowsGuestModuleWriter.cpp
core/relinker/elfpatcher/src/windows/WindowsPePatcher.cpp
core/relinker/elfpatcher/src/windows/WindowsTlsBuilder.cpp
PR 27866 core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp
PR 28006 core/libs/prx/libkernel/System/src/Exception.cpp
PR 28013 core/libs/prx/libkernel/System/src/Exception.cpp
PR 28051 core/libs/prx/libc/src/specifics/windows/CrashReport.cpp
PR 28178 core/relinker/CMakeLists.txt
core/relinker/elfpatcher/src/windows/WindowsRelocationBuilder.cpp
PR 28277 core/relinker/CMakeLists.txt
PR 28299 core/libs/prx/libkernel/System/src/Exception.cpp
PR 28445 core/relinker/CMakeLists.txt
PR 28453 core/relinker/CMakeLists.txt
PR 28671 core/relinker/CMakeLists.txt
PR 28770 core/libs/prx/libkernel/Module/src/DynamicLoader.cpp
core/relinker/CMakeLists.txt
PR 28772 core/relinker/relinker/src/parsing/ElfReader.cpp
core/relinker/relinker/tests/ElfReaderBoundsTests.cpp
PR 28808 core/libs/prx/libkernel/System/src/Exception.cpp
PR 29172 core/libs/prx/libkernel/Module/src/DynamicLoader.cpp
PR 29248 core/libs/prx/libc/src/specifics/windows/CrashReport.cpp
PR 29253 core/libs/prx/libc/src/specifics/windows/CrashReport.cpp
PR 29256 core/libs/prx/libc/src/specifics/windows/CrashReport.cpp
PR 29259 core/relinker/CMakeLists.txt

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 27, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor

Correction to my previous comment, which the shell mangled: I checked the current-main delta in addition to the declared prerequisite stack. This head is based on b986c11, while current main includes #11090 (commit 33b48ba), which changes WindowsTlsBuilder to reject GS traps that would overwrite an executable entry point and adds test_gs_trap_entry_roots.py. This PR also changes that trap-planning path, so the rebase should explicitly preserve the #11090 check and its regression coverage in the VEX case before this can be merge-ready. The PR is already marked needs rebase; I have not submitted a review decision while that integration is unresolved.

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

Follow-up on the refreshed overlap report for 74746df3147c84663716e32f0fd7dc920cbe2ed8. I fetched all 148 listed peer heads and made 180 three-way shared-file comparisons. The 103 conflicting file pairs reproduce the conflicts at the prior VEX head. Neither Python test changed in this follow-up appears in the report.

The inherited Windows startup conflict now includes #18523. Its RELRO protection ranges and the GS runtime setup both need to reach the entry stub and guest module writer. The load image also needs to retain both RELRO range collection and GS relocation tracking. #15245 still shares the entry-stub signature and call site, and #19470’s overflow checks touch the inherited ELF alignment checks. Those are merge-order coordination points for the stack.

#22422 changes the overlapping-instruction check for FS TLS decoding. #24472 adds FMA lowering targets and tests in separate parts of the relinker build. Neither changes the VEX guest GS replay paths. This was a source comparison. The current-main prerequisite conflicts still govern the draft.

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

@MarcZX10 I checked the offset finding on 74746df3147c84663716e32f0fd7dc920cbe2ed8. The emitted frame starts at record + 24 with the five-byte lea rsp, [rsp - 128] (48 8d 64 24 80). The first UD2 (0f 0b) is at record + 29, which is the RIP accepted by the exception lookup. The rewritten guest instruction jumps to +24 to reserve the red zone before it hits that trap. The replay-range query includes the stack adjustment and the terminal UD2. Emitter · Lookup.

I converted a fixture with a conditional branch over an unsupported GS-prefixed VEX instruction to a later supported VEX load. The PE contains the earlier UD2 fallback and a single replay record for the later load. I checked the record bytes and verified the resulting YMM lanes for C4 and C5 at both vector widths in both native Windows runners, including the production-libc runner. All eight combinations passed.

I also reran the focused suite on native Windows with the candidate test scripts and the archived Release binaries whose source inputs were verified against the previous head. 32/32 passed, including both VEX suites, fallback, startup and synthetic --no-avx. Could you recheck the finding against the emitted frame bytes?

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

The refreshed overlap report adds #27532. At VEX head 74746df3147c84663716e32f0fd7dc920cbe2ed8, the source merge preview keeps GS replay handling ahead of CLZERO emulation. A separate preview with published scalar head 5922e359e9a3e74ad8366698f3f15bbd0e7cf4b5 shows a conflict in CrashReport.cpp: both patches insert logic between the SSE4a handler and general host fault delivery.

When composing the stack, keep the CLZERO handler and the scalar GS fault projection and continuation logic. GS replay entry handling should still run first, and each handler should retain its existing exception checks. This was a source comparison. Combined Windows execution remains untested.

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

The refreshed overlap report flags #27848. At VEX head 74746df3147c84663716e32f0fd7dc920cbe2ed8, the source merge preview conflicts in the Windows entry-stub declaration, definition and executable call site. Both patches add an argument at the same position. The integration needs both requiresGuestGsRuntime for GS registration and WindowsTlsLayout for writing bound imports into the TLS template and the startup thread’s TLS block.

The preview already retains guest-module GS registration and the relocation check for borrowed GS followers. The other refreshed peers add no conflicts beyond those against main. Combined execution remains untested.

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

The refreshed overlap report adds #28282. Its source merge preview conflicts with this PR and with the published scalar prerequisite d37ed55b75b2996cd37b778d7606c69863372b82 in the Windows entry-stub declaration, definition, and executable call site. Both changes append an argument to WindowsEntryStubBuilder::Build. If #28282 lands first, the stack integration needs to carry both executableModules for executable-module import binding and requiresGuestGsRuntime for GS runtime registration through the call. The previews for #28277 and #28299 introduce no additional conflicts. These are source merge previews. Combined runtime tests remain pending.

@Felipebmaitan

Copy link
Copy Markdown
Contributor Author

CLZERO support from #27532 has landed. A source merge preview of current main (4a7fd1c405a7ff410d4f2fc1de9cbbdd19ed7d90) and scalar #11628 (d37ed55b75b2996cd37b778d7606c69863372b82) now reproduces the previously reported CrashReport.cpp conflict. It needs to be resolved in #11628 and then carried through #11661 and #11689 so this PR inherits both CLZERO emulation and scalar GS replay-fault projection. A direct preview against the VEX branch shows the same four base conflicts as before, so that preview alone does not cover the pending scalar integration.

This was referenced Dec 2, 2026

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trial merge conflicts in ElfReader.cpp and ElfReaderBoundsTests.cpp. The VEX replay path should retain the native comparison for 128- and 256-bit moves, alignment faults, and upper YMM state. Please keep the host-feature-denial control too. Its conversion should still succeed without AVX and the guest instruction should take its documented fallback at execution. Please use debt fragments for the three library and relinker changes. I reviewed this in source and did not run native Windows tests.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants