Given we are patching the Windows GCC used for releases, to avoid the use of certain aligned assembly instructions, we should probably add a symbol-check test to ensure the patches are working as intended.
contrib: add symbol-check test for non-existence of `vmova` instructions in Windows build #28413
issue fanquake opened this issue on September 5, 2023-
fanquake commented at 12:35 PM on September 5, 2023: member
- fanquake added the label Windows on Sep 5, 2023
-
laanwj commented at 10:32 AM on April 11, 2024: member
Wouldn't checking the instructions be more of a security-check instead of a symbol-check?
Assigning myself as I'm interested on working on this.
- laanwj assigned laanwj on Apr 11, 2024
-
laanwj commented at 8:53 PM on April 14, 2024: member
Is introducing a dependency on the python
capstonebinding acceptable here? It's not possible to do this check without a disassembler of some kind, we don't want to rely on calling out toobjdump, and i'm not sure we want our own x86 mini-disassembler (hard to review, slow in pure python). Capstone is great for this and might help in future instruction security checks as well. But it's another build-time dep. -
laanwj commented at 3:51 AM on April 15, 2024: member
For reference, with capstone this check is as simple as:
# Intel® 64 and IA-32 Architectures Software Developer’s Manual: # chapter 14.9, table 14-22. Instructions Requiring Explicitly Aligned Memory # chapter 15.7, Table 15-6. SIMD Instructions Requiring Explicitly Aligned Memory # # This amounts to the following instructions: # # instruction chapter 4.3 section # --------------------------- --------------------------------- # (V)MOVDQA xmm, mBBB MOVDQA,VMOVDQA32/64—Move Aligned Packed Integer Values # (V)MOVDQA mBBB, xmm MOVDQA,VMOVDQA32/64—Move Aligned Packed Integer Values # (V)MOVAPS xmm, mBBB MOVAPS—Move Aligned Packed Single Precision Floating-Point Values # (V)MOVAPS mBBB, xmm MOVAPS—Move Aligned Packed Single Precision Floating-Point Values # (V)MOVAPD xmm, mBBB MOVAPD—Move Aligned Packed Double Precision Floating-Point Values # (V)MOVAPD mBBB, xmm MOVAPD—Move Aligned Packed Double Precision Floating-Point Values # (V)MOVNTPS mBBB, xmm MOVNTPS—Store Packed Single Precision Floating-Point Values Using Non-Temporal Hint # (V)MOVNTPD mBBB, xmm MOVNTPD—Store Packed Double Precision Floating-Point Values Using Non-Temporal Hint # (V)MOVNTDQ mBBB, xmm MOVNTDQ—Store Packed Integers Using Non-Temporal Hint # (V)MOVNTDQA xmm, mBBB MOVNTDQA—Load Double Quadword Non-Temporal Aligned Hint # # BBB is the bit size, which can be 128, 256 or 512. # FORBIDDEN_VMOVA = { capstone.x86.X86_INS_MOVDQA, capstone.x86.X86_INS_VMOVDQA, capstone.x86.X86_INS_VMOVDQA32, capstone.x86.X86_INS_VMOVDQA64, capstone.x86.X86_INS_MOVAPS, capstone.x86.X86_INS_VMOVAPS, capstone.x86.X86_INS_MOVAPD, capstone.x86.X86_INS_VMOVAPD, capstone.x86.X86_INS_MOVNTPS, capstone.x86.X86_INS_VMOVNTPS, capstone.x86.X86_INS_MOVNTPD, capstone.x86.X86_INS_VMOVNTPD, capstone.x86.X86_INS_MOVNTDQ, capstone.x86.X86_INS_VMOVNTDQ, capstone.x86.X86_INS_MOVNTDQA, capstone.x86.X86_INS_VMOVNTDQA, } def check_ELF_no_vmova(binary) -> bool: ''' Check for vmov instructions that require alignment. These are a potential problem due to a stack alignment bug in GCC on Windows. See [#28413](/bitcoin-bitcoin/28413/) for specifics. ''' cs = capstone.Cs(capstone.CS_ARCH_X86, capstone.CS_MODE_64) found_forbidden = False for segment in binary.segments: # Find loaded, executable segments if segment.type == lief.ELF.SEGMENT_TYPES.LOAD and (segment.flags & lief.ELF.SEGMENT_FLAGS.X) != 0: # disassemble segment, check every instruction for i in cs.disasm(segment.content, segment.virtual_address): # -> CsInsn if i.id in FORBIDDEN_VMOVA: found_forbidden = True return not found_forbiddenStill need to port this to PE.
And figure out what the exceptions are in the current release, and how to either get rid of them, or identify them.
- laanwj referenced this in commit 54f5717379 on Apr 15, 2024
- laanwj referenced this in commit 60d11eb987 on Apr 15, 2024
- laanwj referenced this in commit c21e680a8f on Apr 15, 2024
-
willcl-ark commented at 3:10 PM on October 21, 2025: member
It looks like this issue has been resolved. If that’s not the case, please let us know by commenting here or opening a new issue.
- willcl-ark closed this on Oct 21, 2025