Skip to content

release/23.x: [win/asan] GetInstructionSize: Add some more instructions. (#219038) - #221969

Merged
dyung merged 1 commit into
llvm:release/23.xfrom
llvmbot:issue219038
Sep 16, 2026
Merged

dyung merged 1 commit into
llvm:release/23.xfrom
llvmbot:issue219038

Conversation

@llvmbot

@llvmbot llvmbot commented Sep 8, 2026

Copy link
Copy Markdown
Member

Backport 7fd0dd8

Requested by: @mstorsjo

@llvmbot

llvmbot commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@zmodem What do you think about merging this PR to the release branch?

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: llvmbot

Changes

Backport 7fd0dd8

Requested by: @mstorsjo


Full diff: https://github.com/llvm/llvm-project/pull/221969.diff

2 Files Affected:

  • (modified) compiler-rt/lib/interception/interception_win.cpp (+9-5)
  • (modified) compiler-rt/lib/interception/tests/interception_win_test.cpp (+8-1)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 86a622ed48b50..b43776418f621 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -676,6 +676,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0xC084:  // 84 C0 : test al,al
     case 0xC984:  // 84 C9 : test cl,cl
     case 0xD284:  // 84 D2 : test dl,dl
+    case 0xD285:  // 85 D2 : test edx, edx
       return 2;
 
     case 0x3980:  // 80 39 XX : cmp BYTE PTR [rcx], XX
@@ -699,7 +700,9 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
   }
 
   switch (0x00FFFFFF & *(u32 *)address) {
+    case 0x24448D:  // 8D 44 24 XX : lea eax, [esp + XX]
     case 0x244C8D:  // 8D 4C 24 XX : lea ecx, [esp + XX]
+    case 0x3A8366:  // 66 83 3A XX : cmp word ptr [rdx], XX
     case 0x2474FF:  // FF 74 24 XX : push qword ptr [rsp + XX]
       return 4;
     case 0x24A48D:  // 8D A4 24 XX XX XX XX : lea esp, [esp + XX XX XX XX]
@@ -708,7 +711,12 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
 
   switch (*(u32*)(address)) {
     case 0xc0ef0f66:  // 66 0f ef c0 : pxor xmm0, xmm0
+    case 0xFA1E0FF3:  // F3 0F 1E FA : endbr64
+    case 0xFB1E0FF3:  // F3 0F 1E FB : endbr32
       return 4;
+    case 0x2444B60F:  // 0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]
+    case 0x244CB60F:  // 0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]
+      return 5;
   }
 
   switch (0x000000FF & *(u32 *)address) {
@@ -885,6 +893,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x488d49:    // 49 8d 48 XX : lea rcx, [...]
     case 0x048d4c:    // 4c 8d 04 XX : lea r8, [...]
     case 0x148d4e:    // 4e 8d 14 XX : lea r10, [...]
+    case 0x0C8D4F:    // 4F 8D 0C XX : lea r9, [...]
     case 0x398366:    // 66 83 39 XX : cmp WORD PTR [rcx], XX
       return 4;
 
@@ -1004,11 +1013,6 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x247C8B:  // 8B 7C 24 XX : mov edi, dword ptr [esp + XX]
       return 4;
   }
-
-  switch (*(u32*)address) {
-    case 0x2444B60F:  // 0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]
-      return 5;
-  }
 #endif
 
   // Unknown instruction! This might happen when we add a new interceptor, use
diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp
index 054d5405971dd..d3a52e9007b7a 100644
--- a/compiler-rt/lib/interception/tests/interception_win_test.cpp
+++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp
@@ -852,6 +852,7 @@ const struct InstructionSizeData {
     { 2, {0x84, 0xC9}, 0, "84 C9 : test cl,cl"},
     { 2, {0x84, 0xD2}, 0, "84 D2 : test dl,dl"},
     { 2, {0x84, 0xDB}, 0, "84 DB : test bl,bl"},
+    { 2, {0x85, 0xD2}, 0, "85 D2 : test edx, edx"},
     { 2, {0x89, 0xc8}, 0, "89 C8 : mov eax, ecx"},
     { 2, {0x89, 0xD1}, 0, "89 D1 : mov ecx, edx"},
     { 2, {0x89, 0xE5}, 0, "89 E5 : mov ebp, esp"},
@@ -869,8 +870,14 @@ const struct InstructionSizeData {
     { 3, {0x8D, 0x45, 0x72}, 0, "8D 45 XX : lea eax, [ebp + XX]"},
     { 3, {0xc2, 0x71, 0x72}, 0, "C2 XX XX : ret XX (needed for registering weak functions)"},
     { 4, {0x66, 0x0f, 0xef, 0xc0}, 0, "66 0f ef c0 : pxor xmm0, xmm0"},
+    { 4, {0x66, 0x83, 0x3A, 0x73}, 0, "66 83 3A XX : cmp word ptr [rdx], XX"},
+    { 4, {0x8D, 0x44, 0x24, 0x73}, 0, "8D 44 24 XX : lea eax, [esp + XX]"},
     { 4, {0x8D, 0x4C, 0x24, 0x73}, 0, "8D 4C 24 XX : lea ecx, [esp + XX]"},
+    { 4, {0xF3, 0x0F, 0x1E, 0xFA}, 0, "F3 0F 1E FA : endbr64"},
+    { 4, {0xF3, 0x0F, 0x1E, 0xFB}, 0, "F3 0F 1E FB : endbr32"},
     { 4, {0xFF, 0x74, 0x24, 0x73}, 0, "FF 74 24 XX : push qword ptr [rsp + XX]"},
+    { 5, {0x0F, 0xB6, 0x44, 0x24, 0x74}, 0, "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]"},
+    { 5, {0x0F, 0xB6, 0x4C, 0x24, 0x74}, 0, "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"},
     { 5, {0x68, 0x71, 0x72, 0x73, 0x74}, 0, "68 XX XX XX XX : push imm32"},
     { 5, {0xb8, 0x71, 0x72, 0x73, 0x74}, 0, "b8 XX XX XX XX : mov eax, XX XX XX XX"},
     { 5, {0xB9, 0x71, 0x72, 0x73, 0x74}, 0, "b9 XX XX XX XX : mov ecx, XX XX XX XX"},
@@ -986,6 +993,7 @@ const struct InstructionSizeData {
     { 4, {0x49, 0x8d, 0x48, 0x73}, 0, "49 8d 48 XX : lea rcx, [...]"},
     { 4, {0x4c, 0x8d, 0x04, 0x73}, 0, "4c 8d 04 XX : lea r8, [...]"},
     { 4, {0x4e, 0x8d, 0x14, 0x73}, 0, "4e 8d 14 XX : lea r10, [...]"},
+    { 4, {0x4F, 0x8D, 0x0C, 0x73}, 0, "4F 8D 0C XX : lea r9, [...]"},
     { 4, {0x66, 0x83, 0x39, 0x73}, 0, "66 83 39 XX : cmp WORD PTR [rcx], XX"},
     { 4, {0x80, 0x78, 0x72, 0x73}, 0, "80 78 YY XX : cmp BYTE PTR [rax+YY], XX"},
     { 4, {0x80, 0x79, 0x72, 0x73}, 0, "80 79 YY XX : cmp BYTE ptr [rcx+YY], XX"},
@@ -1070,7 +1078,6 @@ const struct InstructionSizeData {
     { 4, {0x8B, 0x6C, 0x24, 0x73}, 0, "8B 6C 24 XX : mov ebp, dword ptr [esp + XX]"},
     { 4, {0x8B, 0x74, 0x24, 0x73}, 0, "8B 74 24 XX : mov esi, dword ptr [esp + XX]"},
     { 4, {0x8B, 0x7C, 0x24, 0x73}, 0, "8B 7C 24 XX : mov edi, dword ptr [esp + XX]"},
-    { 5, {0x0F, 0xB6, 0x44, 0x24, 0x74}, 0, "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]"},
     { 5, {0xA1, 0x71, 0x72, 0x73, 0x74}, 0, "A1 XX XX XX XX : mov eax, dword ptr ds:[XXXXXXXX]"},
     { 6, {0xF7, 0xC1, 0x72, 0x73, 0x74, 0x75}, 0, "F7 C1 XX YY ZZ WW : test ecx, WWZZYYXX"},
     { 7, {0x83, 0x3D, 0x72, 0x73, 0x74, 0x75, 0x76}, 0, "83 3D XX YY ZZ WW TT : cmp TT, WWZZYYXX"},

@zmodem zmodem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@github-project-automation github-project-automation Bot moved this from Needs Triage to Needs Merge in LLVM Release Status Sep 8, 2026
@dyung

dyung commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

This looks to just be completing a fix that was incomplete before, is that correct?

@mstorsjo

Copy link
Copy Markdown
Member

This looks to just be completing a fix that was incomplete before, is that correct?

Yes, pretty much. (Technically I guess it's hard to say if it is "complete" after this - but if I understood @bernhardu correctly, this patch brings it up to a level where asan works in cases where it didn't before.)

@bernhardu

Copy link
Copy Markdown
Contributor

This looks to just be completing a fix that was incomplete before, is that correct?

Yes, pretty much. (Technically I guess it's hard to say if it is "complete" after this - but if I understood @bernhardu correctly, this patch brings it up to a level where asan works in cases where it didn't before.)

The instructions from !214707 I found only in the Wine upstream packages for Debian 14.
The instructions from !219038 (which are subject of this PR) got found by @hartwork in the Wine downstream packages of several versions of Debian and Ubuntu.

This instructions originate from different compilers or compiler settings used when building these packages.

More or less the same situation if a new native Windows dll uses an unknown instruction in a function to intercept because of a new Windows version or a new Update to the Dll.

Therefore I am not sure if we ever can declare it as complete.

@dyung

dyung commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What are the implications if we do not take this fix on the release branch? Would there be crashes? Bad codegen? Suboptimal ASAN usage?

@mstorsjo

Copy link
Copy Markdown
Member

What are the implications if we do not take this fix on the release branch? Would there be crashes? Bad codegen? Suboptimal ASAN usage?

The implications is that ASAN fails to work in some cases (depending on what compiler has generated code - in this case, in particular when ASAN is used inside Wine).

IMO, the fix is quite safe - it doesn't change how any other existing codepath behaves, but just makes ASAN able to handle more x86 instruction cases that it didn't before. And we're not that deep into the 23.1 release sequence yet, so I think it would be a reasonable change to backport at this point.

@mstorsjo

Copy link
Copy Markdown
Member

This looks to just be completing a fix that was incomplete before, is that correct?

But in one sense, yes, this can indeed be considered as completing a fix that was incomplete.

These got reported in llvm#96270.

- Allow "0F B6 44 24 XX : movzx eax, byte ptr [esp + XX]" for x86 and
x86_64.
- Add "0F B6 4C 24 XX : movzx ecx, byte ptr [esp + XX]"
- Add "4F 8D 0C XX : lea r9, [...]"
- Add "66 83 3A XX : cmp word ptr [rdx], XX"
- Add "85 D2 : test edx, edx"
- Add "8D 44 24 XX : lea eax, [esp + XX]"
- Add "F3 0F 1E FA : endbr64"
- Add "F3 0F 1E FB : endbr32"

(cherry picked from commit 7fd0dd8)
@dyung
dyung merged commit 3c3c37e into llvm:release/23.x Sep 16, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Merge to Done in LLVM Release Status Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

5 participants