Skip to content

[win/asan] GetInstructionSize: Fix 41 81 7c ... to return 9. #117828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

bernhardu
Copy link
Contributor

@bernhardu bernhardu commented Nov 27, 2024

Trying to populate the recently added test for GetInstructionSize I stumbled over this.
gdb and bddisasm have the opinion this instruction is 9 bytes.
Also lldb shows this:

(lldb) disassemble --bytes --start-address 0x0000555555556004 --end-address 0x0000555555556024
    0x555555556004: 41 81 7b 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r11)   ; imm = 0x77767574 
    0x55555555600c: 41 81 7c 73 74 75 76 77 78  cmpl   $0x78777675, 0x74(%r11,%rsi,2) ; imm = 0x78777675 
    0x555555556015: 41 81 7d 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r13)   ; imm = 0x77767574 
    0x55555555601d: 00 00                       addb   %al, (%rax)

There is also a handy tool in llvm to directly feed in the byte sequence - 41 81 7c also uses 9 bytes here:

$ echo -n -e "0x41, 0x81, 0x7b, 0x73, 0x74, 0x75, 0x76, 0x77, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding
        .text
        cmpl    $2004252020, 115(%r11)          # encoding: [0x41,0x81,0x7b,0x73,0x74,0x75,0x76,0x77]
                                        # imm = 0x77767574
        nop                                     # encoding: [0x90]
$ echo -n -e "0x41, 0x81, 0x7c, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x90" | ./llvm/build/bin/llvm-mc --disassemble --show-encoding
        .text
        cmpl    $2021095029, 116(%r11,%rsi,2)   # encoding: [0x41,0x81,0x7c,0x73,0x74,0x75,0x76,0x77,0x78]
                                        # imm = 0x78777675
        nop                                     # encoding: [0x90]

@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2024

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

Author: None (bernhardu)

Changes

Trying to populate the recently added test for GetInstructionSize I stumbled over this.
gdb and bddisasm have the opinion this instruction is 9 bytes.
Also lldb shows this:

(lldb) disassemble --bytes --start-address 0x0000555555556004 --end-address 0x0000555555556024
    0x555555556004: 41 81 7b 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r11)   ; imm = 0x77767574 
    0x55555555600c: 41 81 7c 73 74 75 76 77 78  cmpl   $0x78777675, 0x74(%r11,%rsi,2) ; imm = 0x78777675 
    0x555555556015: 41 81 7d 73 74 75 76 77     cmpl   $0x77767574, 0x73(%r13)   ; imm = 0x77767574 
    0x55555555601d: 00 00                       addb   %al, (%rax)

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

1 Files Affected:

  • (modified) compiler-rt/lib/interception/interception_win.cpp (+4-1)
diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp
index 8767d8e79881c2..db9f922ba8b96b 100644
--- a/compiler-rt/lib/interception/interception_win.cpp
+++ b/compiler-rt/lib/interception/interception_win.cpp
@@ -808,7 +808,6 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x798141:  // 41 81 79 XX YY YY YY YY : cmp DWORD PTR [r9+YY], XX XX XX XX
     case 0x7a8141:  // 41 81 7a XX YY YY YY YY : cmp DWORD PTR [r10+YY], XX XX XX XX
     case 0x7b8141:  // 41 81 7b XX YY YY YY YY : cmp DWORD PTR [r11+YY], XX XX XX XX
-    case 0x7c8141:  // 41 81 7c XX YY YY YY YY : cmp DWORD PTR [r12+YY], XX XX XX XX
     case 0x7d8141:  // 41 81 7d XX YY YY YY YY : cmp DWORD PTR [r13+YY], XX XX XX XX
     case 0x7e8141:  // 41 81 7e XX YY YY YY YY : cmp DWORD PTR [r14+YY], XX XX XX XX
     case 0x7f8141:  // 41 81 7f YY XX XX XX XX : cmp DWORD PTR [r15+YY], XX XX XX XX
@@ -835,6 +834,10 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) {
     case 0x2444c7:    // C7 44 24 XX YY YY YY YY
                       //   mov dword ptr [rsp + XX], YYYYYYYY
       return 8;
+
+    case 0x7c8141:  // 41 81 7c ZZ YY XX XX XX XX
+                    // cmp DWORD PTR [reg+reg*n+YY], XX XX XX XX
+      return 9;
   }
 
   switch (*(u32*)(address)) {

@bernhardu
Copy link
Contributor Author

@zmodem Thanks for the other reviews and merges, may I ask for another review of this one?

Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

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

lgtm

@bernhardu
Copy link
Contributor Author

I would like to change this PR to include the addition of a test line.
But this would need to go in #118204 first, so I hope it is ok if I change this to Draft?

@bernhardu bernhardu marked this pull request as draft December 1, 2024 12:31
@bernhardu bernhardu force-pushed the mr/interception_win/fix-41-81-7c branch from ed1fc05 to 25fd2cd Compare December 6, 2024 16:36
@bernhardu bernhardu force-pushed the mr/interception_win/fix-41-81-7c branch from 25fd2cd to 5520453 Compare December 6, 2024 20:09
@bernhardu bernhardu marked this pull request as ready for review December 6, 2024 20:11
@bernhardu
Copy link
Contributor Author

v2:

  • Rebased to current git

v3:

  • Added the test line.

@bernhardu bernhardu requested a review from zmodem December 6, 2024 20:14
Copy link
Collaborator

@zmodem zmodem left a comment

Choose a reason for hiding this comment

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

lgtm

Would you like me to hit the "merge" button?

@bernhardu
Copy link
Contributor Author

bernhardu commented Dec 9, 2024

Would you like me to hit the "merge" button?

Thanks for reviewing, if there are no more concerns about the change, yes, please.

@zmodem zmodem merged commit 213c90d into llvm:main Dec 9, 2024
9 checks passed
@bernhardu bernhardu deleted the mr/interception_win/fix-41-81-7c branch December 9, 2024 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants