Skip to content

Commit c3fc3bc

Browse files
committedAug 8, 2017
[winasan] Fix hotpatching ntdll!strcpy for Win10 creators edition
The 9 byte nop is a suffix of the 10 byte nop, and we need at most 6 bytes. ntdll's version of strcpy is written in assembly and is very clever. strcat tail calls strcpy but with a slightly different arrangement of argument registers at an alternate entry point. It looks like this: ntdll!strcpy: 00007ffd`64e8a7a0 4c8bd9 mov r11,rcx ntdll!__entry_from_strcat_in_strcpy: 00007ffd`64e8a7a3 482bca sub rcx,rdx 00007ffd`64e8a7a6 f6c207 test dl,7 If we overwrite more than two bytes in our interceptor, that label will no longer be a valid instruction boundary. By recognizing the 9 byte nop, we use the two byte backwards branch to start our trampoline, avoiding this issue. Fixes google/sanitizers#829 Patch by David Major llvm-svn: 310419
1 parent a92a842 commit c3fc3bc

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed
 

‎compiler-rt/lib/interception/interception_win.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ static bool IsMemoryPadding(uptr address, uptr size) {
223223
return true;
224224
}
225225

226-
static const u8 kHintNop10Bytes[] = {
227-
0x66, 0x66, 0x0F, 0x1F, 0x84,
228-
0x00, 0x00, 0x00, 0x00, 0x00
226+
static const u8 kHintNop9Bytes[] = {
227+
0x66, 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
229228
};
230229

231230
template<class T>
@@ -240,8 +239,8 @@ static bool FunctionHasPrefix(uptr address, const T &pattern) {
240239
static bool FunctionHasPadding(uptr address, uptr size) {
241240
if (IsMemoryPadding(address - size, size))
242241
return true;
243-
if (size <= sizeof(kHintNop10Bytes) &&
244-
FunctionHasPrefix(address, kHintNop10Bytes))
242+
if (size <= sizeof(kHintNop9Bytes) &&
243+
FunctionHasPrefix(address, kHintNop9Bytes))
245244
return true;
246245
return false;
247246
}

0 commit comments

Comments
 (0)
Please sign in to comment.